Skip to content

Commit e48a889

Browse files
committed
Add small canvas sample
1 parent cd67e9b commit e48a889

17 files changed

+1686
-7
lines changed

src/CanvasAPI.res

+372
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,108 @@ type offscreenRenderingContextId =
1010
| @as("webgl2") Webgl2
1111
| @as("webgpu") Webgpu
1212

13+
type globalCompositeOperation =
14+
| @as("color") Color
15+
| @as("color-burn") ColorBurn
16+
| @as("color-dodge") ColorDodge
17+
| @as("copy") Copy
18+
| @as("darken") Darken
19+
| @as("destination-atop") DestinationAtop
20+
| @as("destination-in") DestinationIn
21+
| @as("destination-out") DestinationOut
22+
| @as("destination-over") DestinationOver
23+
| @as("difference") Difference
24+
| @as("exclusion") Exclusion
25+
| @as("hard-light") HardLight
26+
| @as("hue") Hue
27+
| @as("lighten") Lighten
28+
| @as("lighter") Lighter
29+
| @as("luminosity") Luminosity
30+
| @as("multiply") Multiply
31+
| @as("overlay") Overlay
32+
| @as("saturation") Saturation
33+
| @as("screen") Screen
34+
| @as("soft-light") SoftLight
35+
| @as("source-atop") SourceAtop
36+
| @as("source-in") SourceIn
37+
| @as("source-out") SourceOut
38+
| @as("source-over") SourceOver
39+
| @as("xor") Xor
40+
41+
type imageSmoothingQuality =
42+
| @as("high") High
43+
| @as("low") Low
44+
| @as("medium") Medium
45+
46+
type canvasLineCap =
47+
| @as("butt") Butt
48+
| @as("round") Round
49+
| @as("square") Square
50+
51+
type canvasLineJoin =
52+
| @as("bevel") Bevel
53+
| @as("miter") Miter
54+
| @as("round") Round
55+
56+
type canvasTextAlign =
57+
| @as("center") Center
58+
| @as("end") End
59+
| @as("left") Left
60+
| @as("right") Right
61+
| @as("start") Start
62+
63+
type canvasTextBaseline =
64+
| @as("alphabetic") Alphabetic
65+
| @as("bottom") Bottom
66+
| @as("hanging") Hanging
67+
| @as("ideographic") Ideographic
68+
| @as("middle") Middle
69+
| @as("top") Top
70+
71+
type canvasDirection =
72+
| @as("inherit") Inherit
73+
| @as("ltr") Ltr
74+
| @as("rtl") Rtl
75+
76+
type canvasFontKerning =
77+
| @as("auto") Auto
78+
| @as("none") None
79+
| @as("normal") Normal
80+
81+
type canvasFontStretch =
82+
| @as("condensed") Condensed
83+
| @as("expanded") Expanded
84+
| @as("extra-condensed") ExtraCondensed
85+
| @as("extra-expanded") ExtraExpanded
86+
| @as("normal") Normal
87+
| @as("semi-condensed") SemiCondensed
88+
| @as("semi-expanded") SemiExpanded
89+
| @as("ultra-condensed") UltraCondensed
90+
| @as("ultra-expanded") UltraExpanded
91+
92+
type canvasFontVariantCaps =
93+
| @as("all-petite-caps") AllPetiteCaps
94+
| @as("all-small-caps") AllSmallCaps
95+
| @as("normal") Normal
96+
| @as("petite-caps") PetiteCaps
97+
| @as("small-caps") SmallCaps
98+
| @as("titling-caps") TitlingCaps
99+
| @as("unicase") Unicase
100+
101+
type canvasTextRendering =
102+
| @as("auto") Auto
103+
| @as("geometricPrecision") GeometricPrecision
104+
| @as("optimizeLegibility") OptimizeLegibility
105+
| @as("optimizeSpeed") OptimizeSpeed
106+
107+
type predefinedColorSpace =
108+
| @as("display-p3") DisplayP3
109+
| @as("srgb") Srgb
110+
111+
type canvasFillRule =
112+
| @as("evenodd") Evenodd
113+
| @as("nonzero") Nonzero
114+
13115
/**
14116
[See OffscreenCanvas on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvas)
15117
*/
@@ -47,9 +149,279 @@ type imageBitmap = {
47149
height: int,
48150
}
49151

152+
/**
153+
[See OffscreenCanvasRenderingContext2D on MDN](https://developer.mozilla.org/docs/Web/API/OffscreenCanvasRenderingContext2D)
154+
*/
155+
type offscreenCanvasRenderingContext2D = {
156+
/**
157+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/canvas)
158+
*/
159+
canvas: offscreenCanvas,
160+
/**
161+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/globalAlpha)
162+
*/
163+
mutable globalAlpha: float,
164+
/**
165+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation)
166+
*/
167+
mutable globalCompositeOperation: globalCompositeOperation,
168+
/**
169+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled)
170+
*/
171+
mutable imageSmoothingEnabled: bool,
172+
/**
173+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/imageSmoothingQuality)
174+
*/
175+
mutable imageSmoothingQuality: imageSmoothingQuality,
176+
/**
177+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/strokeStyle)
178+
*/
179+
mutable strokeStyle: unknown,
180+
/**
181+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/fillStyle)
182+
*/
183+
mutable fillStyle: unknown,
184+
/**
185+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/shadowOffsetX)
186+
*/
187+
mutable shadowOffsetX: float,
188+
/**
189+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/shadowOffsetY)
190+
*/
191+
mutable shadowOffsetY: float,
192+
/**
193+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/shadowBlur)
194+
*/
195+
mutable shadowBlur: float,
196+
/**
197+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/shadowColor)
198+
*/
199+
mutable shadowColor: string,
200+
/**
201+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/filter)
202+
*/
203+
mutable filter: string,
204+
/**
205+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/lineWidth)
206+
*/
207+
mutable lineWidth: float,
208+
/**
209+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/lineCap)
210+
*/
211+
mutable lineCap: canvasLineCap,
212+
/**
213+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/lineJoin)
214+
*/
215+
mutable lineJoin: canvasLineJoin,
216+
/**
217+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/miterLimit)
218+
*/
219+
mutable miterLimit: float,
220+
/**
221+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
222+
*/
223+
mutable lineDashOffset: float,
224+
/**
225+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/font)
226+
*/
227+
mutable font: string,
228+
/**
229+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/textAlign)
230+
*/
231+
mutable textAlign: canvasTextAlign,
232+
/**
233+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/textBaseline)
234+
*/
235+
mutable textBaseline: canvasTextBaseline,
236+
/**
237+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/direction)
238+
*/
239+
mutable direction: canvasDirection,
240+
/**
241+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/letterSpacing)
242+
*/
243+
mutable letterSpacing: string,
244+
/**
245+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/fontKerning)
246+
*/
247+
mutable fontKerning: canvasFontKerning,
248+
/**
249+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/fontStretch)
250+
*/
251+
mutable fontStretch: canvasFontStretch,
252+
/**
253+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/fontVariantCaps)
254+
*/
255+
mutable fontVariantCaps: canvasFontVariantCaps,
256+
/**
257+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/textRendering)
258+
*/
259+
mutable textRendering: canvasTextRendering,
260+
/**
261+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/wordSpacing)
262+
*/
263+
mutable wordSpacing: string,
264+
}
265+
266+
/**
267+
[See ImageBitmapRenderingContext on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmapRenderingContext)
268+
*/
269+
type imageBitmapRenderingContext = {
270+
/**
271+
Returns the canvas element that the context is bound to.
272+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/ImageBitmapRenderingContext/canvas)
273+
*/
274+
canvas: unknown,
275+
}
276+
277+
/**
278+
Provides an interface to the OpenGL ES 2.0 graphics rendering context for the drawing surface of an HTML <canvas> element.
279+
[See WebGLRenderingContext on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext)
280+
*/
281+
type webGLRenderingContext = {
282+
/**
283+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/canvas)
284+
*/
285+
canvas: unknown,
286+
/**
287+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/drawingBufferWidth)
288+
*/
289+
drawingBufferWidth: float,
290+
/**
291+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/drawingBufferHeight)
292+
*/
293+
drawingBufferHeight: float,
294+
/**
295+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/drawingBufferColorSpace)
296+
*/
297+
mutable drawingBufferColorSpace: predefinedColorSpace,
298+
/**
299+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext/unpackColorSpace)
300+
*/
301+
mutable unpackColorSpace: predefinedColorSpace,
302+
}
303+
304+
/**
305+
[See WebGL2RenderingContext on MDN](https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext)
306+
*/
307+
type webGL2RenderingContext = {
308+
/**
309+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/canvas)
310+
*/
311+
canvas: unknown,
312+
/**
313+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/drawingBufferWidth)
314+
*/
315+
drawingBufferWidth: float,
316+
/**
317+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/drawingBufferHeight)
318+
*/
319+
drawingBufferHeight: float,
320+
/**
321+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/drawingBufferColorSpace)
322+
*/
323+
mutable drawingBufferColorSpace: predefinedColorSpace,
324+
/**
325+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext/unpackColorSpace)
326+
*/
327+
mutable unpackColorSpace: predefinedColorSpace,
328+
}
329+
330+
/**
331+
An opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient().
332+
[See CanvasGradient on MDN](https://developer.mozilla.org/docs/Web/API/CanvasGradient)
333+
*/
334+
type canvasGradient = {}
335+
336+
/**
337+
An opaque object describing a pattern, based on an image, a canvas, or a video, created by the CanvasRenderingContext2D.createPattern() method.
338+
[See CanvasPattern on MDN](https://developer.mozilla.org/docs/Web/API/CanvasPattern)
339+
*/
340+
type canvasPattern = {}
341+
342+
/**
343+
This Canvas 2D API interface is used to declare a path that can then be used on a CanvasRenderingContext2D object. The path methods of the CanvasRenderingContext2D interface are also present on this interface, which gives you the convenience of being able to retain and replay your path whenever desired.
344+
[See Path2D on MDN](https://developer.mozilla.org/docs/Web/API/Path2D)
345+
*/
346+
type path2D = {}
347+
348+
/**
349+
The dimensions of a piece of text in the canvas, as created by the CanvasRenderingContext2D.measureText() method.
350+
[See TextMetrics on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics)
351+
*/
352+
type textMetrics = {
353+
/**
354+
Returns the measurement described below.
355+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/width)
356+
*/
357+
width: float,
358+
/**
359+
Returns the measurement described below.
360+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/actualBoundingBoxLeft)
361+
*/
362+
actualBoundingBoxLeft: float,
363+
/**
364+
Returns the measurement described below.
365+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/actualBoundingBoxRight)
366+
*/
367+
actualBoundingBoxRight: float,
368+
/**
369+
Returns the measurement described below.
370+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/fontBoundingBoxAscent)
371+
*/
372+
fontBoundingBoxAscent: float,
373+
/**
374+
Returns the measurement described below.
375+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/fontBoundingBoxDescent)
376+
*/
377+
fontBoundingBoxDescent: float,
378+
/**
379+
Returns the measurement described below.
380+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/actualBoundingBoxAscent)
381+
*/
382+
actualBoundingBoxAscent: float,
383+
/**
384+
Returns the measurement described below.
385+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/actualBoundingBoxDescent)
386+
*/
387+
actualBoundingBoxDescent: float,
388+
/**
389+
Returns the measurement described below.
390+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/emHeightAscent)
391+
*/
392+
emHeightAscent: float,
393+
/**
394+
Returns the measurement described below.
395+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/emHeightDescent)
396+
*/
397+
emHeightDescent: float,
398+
/**
399+
Returns the measurement described below.
400+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/hangingBaseline)
401+
*/
402+
hangingBaseline: float,
403+
/**
404+
Returns the measurement described below.
405+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/alphabeticBaseline)
406+
*/
407+
alphabeticBaseline: float,
408+
/**
409+
Returns the measurement described below.
410+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TextMetrics/ideographicBaseline)
411+
*/
412+
ideographicBaseline: float,
413+
}
414+
50415
type offscreenRenderingContext = any
51416

52417
type imageEncodeOptions = {
53418
@as("type") mutable type_?: string,
54419
mutable quality?: float,
55420
}
421+
422+
type canvasRenderingContext2DSettings = {
423+
mutable alpha?: bool,
424+
mutable desynchronized?: bool,
425+
mutable colorSpace?: predefinedColorSpace,
426+
mutable willReadFrequently?: bool,
427+
}

src/CanvasAPI/CanvasGradient.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)