Skip to content

Commit d591da9

Browse files
authored
Merge pull request #211 from rescript-lang/moar-bindings
Improve bindings
2 parents b168970 + d2608bc commit d591da9

File tree

11 files changed

+64
-14
lines changed

11 files changed

+64
-14
lines changed

src/CanvasAPI/OffscreenCanvas.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Returns null if the canvas has already been initialized with another context typ
1818
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/getContext)
1919
*/
2020
@send
21-
external getContext_2D: (
21+
external getContext2D: (
2222
offscreenCanvas,
2323
@as("2d") _,
2424
~options: JSON.t=?,
@@ -33,7 +33,7 @@ Returns null if the canvas has already been initialized with another context typ
3333
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/getContext)
3434
*/
3535
@send
36-
external getContext_WebGL: (
36+
external getContextWebGL: (
3737
offscreenCanvas,
3838
@as("webgl") _,
3939
~options: webGLContextAttributes=?,
@@ -48,7 +48,7 @@ Returns null if the canvas has already been initialized with another context typ
4848
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/getContext)
4949
*/
5050
@send
51-
external getContext_WebGL2: (
51+
external getContextWebGL2: (
5252
offscreenCanvas,
5353
@as("webgl2") _,
5454
~options: webGLContextAttributes=?,
@@ -63,7 +63,7 @@ Returns null if the canvas has already been initialized with another context typ
6363
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas/getContext)
6464
*/
6565
@send
66-
external getContext_BitmapRenderer: (
66+
external getContextBitmapRenderer: (
6767
offscreenCanvas,
6868
@as("bitmaprenderer") _,
6969
~options: imageBitmapRenderingContextSettings=?,

src/DOMAPI/Element.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ element->Element.scrollIntoView_alignToTop()
411411
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Element/scrollIntoView)
412412
*/
413413
@send
414-
external scrollIntoView_alignToTop: (T.t, @as(json`true`) _) => unit = "scrollIntoView"
414+
external scrollIntoViewAlignToTop: (T.t, @as(json`true`) _) => unit = "scrollIntoView"
415415

416416
/**
417417
`scrollIntoView({ behavior: "smooth" })`

src/DOMAPI/FileList.res

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ open FileAPI
22
open DOMAPI
33

44
/**
5+
Returns the `File` at the specified index.
6+
7+
`FileList` is not an array, so you need to iterate manually using `length` and `item`:
8+
9+
```rescript
10+
let files = []
11+
for i in 0 to fileList.length - 1 {
12+
files->Array.push(fileList->FileList.item(i))
13+
}
14+
```
15+
516
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FileList/item)
617
*/
718
@send

src/DOMAPI/HTMLCanvasElement.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Creates a CanvasRenderingContext2D object representing a two-dimensional renderi
1111
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#2d)
1212
*/
1313
@send
14-
external getContext_2D: (
14+
external getContext2D: (
1515
htmlCanvasElement,
1616
@as("2d") _,
1717
~options: canvasRenderingContext2DSettings=?,
@@ -23,7 +23,7 @@ Returns an object that provides methods and properties for drawing and manipulat
2323
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/getContext)
2424
*/
2525
@send
26-
external getContext_WebGL: (
26+
external getContextWebGL: (
2727
htmlCanvasElement,
2828
@as("webgl") _,
2929
~options: webGLContextAttributes=?,
@@ -35,7 +35,7 @@ Returns an object that provides methods and properties for drawing and manipulat
3535
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/getContext)
3636
*/
3737
@send
38-
external getContext_WebGL2: (
38+
external getContextWebGL2: (
3939
htmlCanvasElement,
4040
@as("webgl2") _,
4141
~options: webGLContextAttributes=?,
@@ -47,7 +47,7 @@ Returns an object that provides methods and properties for drawing and manipulat
4747
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/getContext)
4848
*/
4949
@send
50-
external getContext_BitmapRenderer: (
50+
external getContextBitmapRenderer: (
5151
htmlCanvasElement,
5252
@as("bitmaprenderer") _,
5353
~options: imageBitmapRenderingContextSettings=?,

src/EventAPI.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@unboxed
44
type eventType =
55
| @as("abort") Abort
6+
| @as("activate") Activate
67
| @as("auxclick") Auxclick
78
| @as("beforeinput") Beforeinput
89
| @as("beforetoggle") Beforetoggle
@@ -35,6 +36,7 @@ type eventType =
3536
| @as("focus") Focus
3637
| @as("formdata") Formdata
3738
| @as("input") Input
39+
| @as("install") Install
3840
| @as("invalid") Invalid
3941
| @as("keydown") Keydown
4042
| @as("keypress") Keypress

src/EventAPI/EventTarget.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Removes the event listener in target's event listener list with the same type, c
7878
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
7979
*/
8080
@send
81-
external removeEventListener_useCapture: (
81+
external removeEventListenerUseCapture: (
8282
T.t,
8383
eventType,
8484
eventListener<'event>,

src/Global.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ external removeEventListener: (
574574
Removes the event listener in target's event listener list with the same type, callback, and options.
575575
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
576576
*/
577-
external removeEventListener_useCapture: (
577+
external removeEventListenerUseCapture: (
578578
eventType,
579579
eventListener<'event>,
580580
@as(json`true`) _,

src/ServiceWorkerAPI/Clients.res

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
open ServiceWorkerAPI
22

3+
type clientQueryOptions = {
4+
mutable includeUncontrolled?: bool,
5+
@as("type") mutable type_?: string,
6+
}
7+
8+
/**
9+
Returns a `Promise` for a `Client` matching a given id.
10+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Clients/get)
11+
*/
12+
@send
13+
external get: (clients, string) => promise<Nullable.t<client>> = "get"
14+
15+
/**
16+
Returns a `Promise` for an array of `Client` objects matching the given options.
17+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Clients/matchAll)
18+
*/
19+
@send
20+
external matchAll: (clients, ~options: clientQueryOptions=?) => promise<array<client>> = "matchAll"
21+
22+
/**
23+
Opens a new browser window for a given URL and returns a `Promise` for the new `WindowClient`.
24+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Clients/openWindow)
25+
*/
26+
@send
27+
external openWindow: (clients, string) => promise<windowClient> = "openWindow"
28+
29+
/**
30+
Allows an active service worker to set itself as the controller for all clients within its scope.
31+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Clients/claim)
32+
*/
333
@send
4-
external openWindow: (clients, string) => promise<windowClient> = "open"
34+
external claim: clients => promise<unit> = "claim"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
open ServiceWorkerAPI
22

33
include WorkerGlobalScope.Impl({type t = serviceWorkerGlobalScope})
4+
5+
/**
6+
Forces the waiting service worker to become the active service worker.
7+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting)
8+
*/
9+
@send
10+
external skipWaiting: serviceWorkerGlobalScope => promise<unit> = "skipWaiting"

tests/DOMAPI/HTMLCanvasElement__test.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ open WebAPI.Global
22

33
let myCanvas: DOMAPI.htmlCanvasElement =
44
document->Document.getElementById("myCanvas")->Prelude.unsafeConversation
5-
let ctx = myCanvas->HTMLCanvasElement.getContext_2D
5+
let ctx = myCanvas->HTMLCanvasElement.getContext2D
66

77
ctx.fillStyle = FillStyle.fromString("red")
88
ctx->CanvasRenderingContext2D.fillRect(~x=50., ~y=50., ~w=200., ~h=200.)

0 commit comments

Comments
 (0)