• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Minimum TypeScript Version: 4.4
2/// <reference types="@webgpu/types" />
3
4export default function CanvasKitInit(opts: CanvasKitInitOptions): Promise<CanvasKit>;
5
6export interface CanvasKitInitOptions {
7    /**
8     * This callback will be invoked when the CanvasKit loader needs to fetch a file (e.g.
9     * the blob of WASM code). The correct url prefix should be applied.
10     * @param file - the name of the file that is about to be loaded.
11     */
12    locateFile(file: string): string;
13}
14
15export interface CanvasKit {
16    // Helpers
17    /**
18     * Constructs a Color with the same API as CSS's rgba(), that is
19     * Internally, Colors are four unpremultiplied 32-bit floats: r, g, b, a.
20     * In order to construct one with more precision or in a wider gamut,
21     * use CanvasKit.Color4f().
22     *
23     * @param r - red value, clamped to [0, 255].
24     * @param g - green value, clamped to [0, 255].
25     * @param b - blue value, clamped to [0, 255].
26     * @param a - alpha value, from 0 to 1.0. By default is 1.0 (opaque).
27     */
28    Color(r: number, g: number, b: number, a?: number): Color;
29
30    /**
31     * Construct a 4-float color. Float values are typically between 0.0 and 1.0.
32     * @param r - red value.
33     * @param g - green value.
34     * @param b - blue value.
35     * @param a - alpha value. By default is 1.0 (opaque).
36     */
37    Color4f(r: number, g: number, b: number, a?: number): Color;
38
39    /**
40     * Constructs a Color as a 32 bit unsigned integer, with 8 bits assigned to each channel.
41     * Channels are expected to be between 0 and 255 and will be clamped as such.
42     * If a is omitted, it will be 255 (opaque).
43     *
44     * This is not the preferred way to use colors in Skia APIs, use Color or Color4f.
45     * @param r - red value, clamped to [0, 255].
46     * @param g - green value, clamped to [0, 255].
47     * @param b - blue value, clamped to [0, 255].
48     * @param a - alpha value, from 0 to 1.0. By default is 1.0 (opaque).
49     */
50    ColorAsInt(r: number, g: number, b: number, a?: number): ColorInt;
51
52    /**
53     * Returns a css style [r, g, b, a] where r, g, b are returned as
54     * ints in the range [0, 255] and where a is scaled between 0 and 1.0.
55     * [Deprecated] - this is trivial now that Color is 4 floats.
56     */
57    getColorComponents(c: Color): number[];
58
59    /**
60     * Takes in a CSS color value and returns a CanvasKit.Color
61     * (which is an array of 4 floats in RGBA order). An optional colorMap
62     * may be provided which maps custom strings to values.
63     * In the CanvasKit canvas2d shim layer, we provide this map for processing
64     * canvas2d calls, but not here for code size reasons.
65     */
66    parseColorString(color: string, colorMap?: Record<string, Color>): Color;
67
68    /**
69     * Returns a copy of the passed in color with a new alpha value applied.
70     * [Deprecated] - this is trivial now that Color is 4 floats.
71     */
72    multiplyByAlpha(c: Color, alpha: number): Color;
73
74    /**
75     * Computes color values for one-pass tonal alpha.
76     * Note, if malloced colors are passed in, the memory pointed at by the MallocObj
77     * will be overwritten with the computed tonal colors (and thus the return val can be
78     * ignored).
79     * @param colors
80     */
81    computeTonalColors(colors: TonalColorsInput): TonalColorsOutput;
82
83    /**
84     * Returns a rectangle with the given paramaters. See Rect.h for more.
85     * @param left - The x coordinate of the upper-left corner.
86     * @param top  - The y coordinate of the upper-left corner.
87     * @param right - The x coordinate of the lower-right corner.
88     * @param bottom - The y coordinate of the lower-right corner.
89     */
90    LTRBRect(left: number, top: number, right: number, bottom: number): Rect;
91
92    /**
93     * Returns a rectangle with the given paramaters. See Rect.h for more.
94     * @param x - The x coordinate of the upper-left corner.
95     * @param y  - The y coordinate of the upper-left corner.
96     * @param width - The width of the rectangle.
97     * @param height - The height of the rectangle.
98     */
99    XYWHRect(x: number, y: number, width: number, height: number): Rect;
100
101    /**
102     * Returns a rectangle with the given integer paramaters. See Rect.h for more.
103     * @param left - The x coordinate of the upper-left corner.
104     * @param top  - The y coordinate of the upper-left corner.
105     * @param right - The x coordinate of the lower-right corner.
106     * @param bottom - The y coordinate of the lower-right corner.
107     */
108    LTRBiRect(left: number, top: number, right: number, bottom: number): IRect;
109
110    /**
111     * Returns a rectangle with the given paramaters. See Rect.h for more.
112     * @param x - The x coordinate of the upper-left corner.
113     * @param y  - The y coordinate of the upper-left corner.
114     * @param width - The width of the rectangle.
115     * @param height - The height of the rectangle.
116     */
117    XYWHiRect(x: number, y: number, width: number, height: number): IRect;
118
119    /**
120     * Returns a rectangle with rounded corners consisting of the given rectangle and
121     * the same radiusX and radiusY for all four corners.
122     * @param rect - The base rectangle.
123     * @param rx - The radius of the corners in the x direction.
124     * @param ry - The radius of the corners in the y direction.
125     */
126    RRectXY(rect: InputRect, rx: number, ry: number): RRect;
127
128    /**
129     * Generate bounding box for shadows relative to path. Includes both the ambient and spot
130     * shadow bounds. This pairs with Canvas.drawShadow().
131     * See SkShadowUtils.h for more details.
132     * @param ctm - Current transformation matrix to device space.
133     * @param path - The occluder used to generate the shadows.
134     * @param zPlaneParams - Values for the plane function which returns the Z offset of the
135     *                       occluder from the canvas based on local x and y values (the current
136     *                       matrix is not applied).
137     * @param lightPos - The 3D position of the light relative to the canvas plane. This is
138     *                   independent of the canvas's current matrix.
139     * @param lightRadius - The radius of the disc light.
140     * @param flags - See SkShadowFlags.h; 0 means use default options.
141     * @param dstRect - if provided, the bounds will be copied into this rect instead of allocating
142     *                  a new one.
143     * @returns The bounding rectangle or null if it could not be computed.
144     */
145    getShadowLocalBounds(ctm: InputMatrix, path: Path, zPlaneParams: InputVector3,
146                         lightPos: InputVector3, lightRadius: number, flags: number,
147                         dstRect?: Rect): Rect | null;
148
149    /**
150     * Malloc returns a TypedArray backed by the C++ memory of the
151     * given length. It should only be used by advanced users who
152     * can manage memory and initialize values properly. When used
153     * correctly, it can save copying of data between JS and C++.
154     * When used incorrectly, it can lead to memory leaks.
155     * Any memory allocated by CanvasKit.Malloc needs to be released with CanvasKit.Free.
156     *
157     * const mObj = CanvasKit.Malloc(Float32Array, 20);
158     * Get a TypedArray view around the malloc'd memory (this does not copy anything).
159     * const ta = mObj.toTypedArray();
160     * // store data into ta
161     * const cf = CanvasKit.ColorFilter.MakeMatrix(ta); // mObj could also be used.
162     *
163     * // eventually...
164     * CanvasKit.Free(mObj);
165     *
166     * @param typedArray - constructor for the typedArray.
167     * @param len - number of *elements* to store.
168     */
169    Malloc(typedArray: TypedArrayConstructor, len: number): MallocObj;
170
171    /**
172     * As Malloc but for GlyphIDs. This helper exists to make sure the JS side and the C++ side
173     * stay in agreement with how wide GlyphIDs are.
174     * @param len - number of GlyphIDs to make space for.
175     */
176    MallocGlyphIDs(len: number): MallocObj;
177
178    /**
179     * Free frees the memory returned by Malloc.
180     * Any memory allocated by CanvasKit.Malloc needs to be released with CanvasKit.Free.
181     */
182    Free(m: MallocObj): void;
183
184    // Surface related functions
185    /**
186     * Creates a Surface on a given canvas. If both GPU and CPU modes have been compiled in, this
187     * will first try to create a GPU surface and then fallback to a CPU one if that fails. If just
188     * the CPU mode has been compiled in, a CPU surface will be created.
189     * @param canvas - either the canvas element itself or a string with the DOM id of it.
190     * @deprecated - Use MakeSWCanvasSurface, MakeWebGLCanvasSurface, or MakeGPUCanvasSurface.
191     */
192    MakeCanvasSurface(canvas: HTMLCanvasElement | string): Surface | null;
193
194    /**
195     * Creates a Raster (CPU) Surface that will draw into the provided Malloc'd buffer. This allows
196     * clients to efficiently be able to read the current pixels w/o having to copy.
197     * The length of pixels must be at least height * bytesPerRow bytes big.
198     * @param ii
199     * @param pixels
200     * @param bytesPerRow - How many bytes are per row. This is at least width * bytesPerColorType. For example,
201     *                      an 8888 ColorType has 4 bytes per pixel, so a 5 pixel wide 8888 surface needs at least
202     *                      5 * 4 = 20 bytesPerRow. Some clients may have more than the usual to make the data line
203     *                      up with a particular multiple.
204     */
205    MakeRasterDirectSurface(ii: ImageInfo, pixels: MallocObj, bytesPerRow: number): Surface | null;
206
207    /**
208     * Creates a CPU backed (aka raster) surface.
209     * @param canvas - either the canvas element itself or a string with the DOM id of it.
210     */
211    MakeSWCanvasSurface(canvas: HTMLCanvasElement | string): Surface | null;
212
213    /**
214     * A helper for creating a WebGL backed (aka GPU) surface and falling back to a CPU surface if
215     * the GPU one cannot be created. This works for both WebGL 1 and WebGL 2.
216     * @param canvas - Either the canvas element itself or a string with the DOM id of it.
217     * @param colorSpace - One of the supported color spaces. Default is SRGB.
218     * @param opts - Options that will get passed to the creation of the WebGL context.
219     */
220    MakeWebGLCanvasSurface(canvas: HTMLCanvasElement | string, colorSpace?: ColorSpace,
221                           opts?: WebGLOptions): Surface | null;
222
223    /**
224     * Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul
225     * alphaType and 8888 color type. The pixels belonging to this surface  will be in memory and
226     * not visible.
227     * @param width - number of pixels of the width of the drawable area.
228     * @param height - number of pixels of the height of the drawable area.
229     */
230    MakeSurface(width: number, height: number): Surface | null;
231
232    /**
233     * Creates a WebGL Context from the given canvas with the given options. If options are omitted,
234     * sensible defaults will be used.
235     * @param canvas
236     * @param opts
237     */
238    GetWebGLContext(canvas: HTMLCanvasElement, opts?: WebGLOptions): WebGLContextHandle;
239
240    /**
241     * Creates a GrDirectContext from the given WebGL Context.
242     * @param ctx
243     * @deprecated Use MakeWebGLContext instead.
244     */
245    MakeGrContext(ctx: WebGLContextHandle): GrDirectContext | null;
246
247    /**
248     * Creates a GrDirectContext from the given WebGL Context.
249     * @param ctx
250     */
251    MakeWebGLContext(ctx: WebGLContextHandle): GrDirectContext | null;
252
253    /**
254     * Creates a Surface that will be drawn to the given GrDirectContext (and show up on screen).
255     * @param ctx
256     * @param width - number of pixels of the width of the visible area.
257     * @param height - number of pixels of the height of the visible area.
258     * @param colorSpace
259     * @param sampleCount - sample count value from GL_SAMPLES. If not provided this will be looked up from
260     *                      the canvas.
261     * @param stencil - stencil count value from GL_STENCIL_BITS. If not provided this will be looked up
262     *                  from the WebGL Context.
263     */
264    MakeOnScreenGLSurface(ctx: GrDirectContext, width: number, height: number,
265                          colorSpace: ColorSpace, sampleCount?: number, stencil?: number): Surface | null;
266
267    /**
268     * Creates a context that operates over the given WebGPU Device.
269     * @param device
270     */
271    MakeGPUDeviceContext(device: GPUDevice): WebGPUDeviceContext | null;
272
273    /**
274     * Creates a Surface that draws to the given GPU texture.
275     * @param ctx
276     * @param texture - A texture that was created on the GPU device associated with `ctx`.
277     * @param width - Width of the visible region in pixels.
278     * @param height - Height of the visible region in pixels.
279     * @param colorSpace
280     */
281    MakeGPUTextureSurface(ctx: WebGPUDeviceContext, texture: GPUTexture, width: number, height: number,
282                          colorSpace: ColorSpace): Surface | null;
283
284    /**
285     * Creates and configures a WebGPU context for the given canvas.
286     * @param ctx
287     * @param canvas
288     * @param opts
289     */
290    MakeGPUCanvasContext(ctx: WebGPUDeviceContext, canvas: HTMLCanvasElement,
291                         opts?: WebGPUCanvasOptions): WebGPUCanvasContext | null;
292
293    /**
294     * Creates a Surface backed by the next available texture in the swapchain associated with the
295     * given WebGPU canvas context. The context must have been already successfully configured using
296     * the same GPUDevice associated with `ctx`.
297     * @param canvasContext - WebGPU context associated with the canvas. The canvas can either be an
298     *                        on-screen HTMLCanvasElement or an OffscreenCanvas.
299     * @param colorSpace
300     * @param width - width of the visible region. If not present, the canvas width from `canvasContext`
301     *                is used.
302     * @param height - height of the visible region. If not present, the canvas width from `canvasContext`
303     *                is used.
304     */
305    MakeGPUCanvasSurface(canvasContext: WebGPUCanvasContext, colorSpace: ColorSpace,
306                         width?: number, height?: number): Surface | null;
307
308    /**
309     * Returns a (non-visible) Surface on the GPU. It has the given dimensions and uses 8888
310     * color depth and premultiplied alpha. See Surface.h for more details.
311     * @param ctx
312     * @param width
313     * @param height
314     */
315    MakeRenderTarget(ctx: GrDirectContext, width: number, height: number): Surface | null;
316
317    /**
318     * Returns a (non-visible) Surface on the GPU. It has the settings provided by image info.
319     * See Surface.h for more details.
320     * @param ctx
321     * @param info
322     */
323    MakeRenderTarget(ctx: GrDirectContext, info: ImageInfo): Surface | null;
324
325    /**
326     * Returns a texture-backed image based on the content in src. It assumes the image is
327     * RGBA_8888, unpremul and SRGB. This image can be re-used across multiple surfaces.
328     *
329     * Not available for software-backed surfaces.
330     * @param src - CanvasKit will take ownership of the TextureSource and clean it up when
331     *              the image is destroyed.
332     * @param info - If provided, will be used to determine the width/height/format of the
333     *               source image. If not, sensible defaults will be used.
334     * @param srcIsPremul - set to true if the src data has premultiplied alpha. Otherwise, it will
335     *         be assumed to be Unpremultiplied. Note: if this is true and info specifies
336     *         Unpremul, Skia will not convert the src pixels first.
337     */
338    MakeLazyImageFromTextureSource(src: TextureSource, info?: ImageInfo | PartialImageInfo,
339                                   srcIsPremul?: boolean): Image;
340
341    /**
342     * Deletes the associated WebGLContext. Function not available on the CPU version.
343     * @param ctx
344     */
345    deleteContext(ctx: WebGLContextHandle): void;
346
347    /**
348     * Returns the max size of the global cache for bitmaps used by CanvasKit.
349     */
350    getDecodeCacheLimitBytes(): number;
351    /**
352     * Returns the current size of the global cache for bitmaps used by CanvasKit.
353     */
354    getDecodeCacheUsedBytes(): number;
355
356    /**
357     * Sets the max size of the global cache for bitmaps used by CanvasKit.
358     * @param size - number of bytes that can be used to cache bitmaps.
359     */
360    setDecodeCacheLimitBytes(size: number): void;
361
362    /**
363     * Decodes the given bytes into an animated image. Returns null if the bytes were invalid.
364     * The passed in bytes will be copied into the WASM heap, so the caller can dispose of them.
365     *
366     * The returned AnimatedImage will be "pointing to" the first frame, i.e. currentFrameDuration
367     * and makeImageAtCurrentFrame will be referring to the first frame.
368     * @param bytes
369     */
370    MakeAnimatedImageFromEncoded(bytes: Uint8Array | ArrayBuffer): AnimatedImage | null;
371
372    /**
373     * Returns an emulated Canvas2D of the given size.
374     * @param width
375     * @param height
376     */
377    MakeCanvas(width: number, height: number): EmulatedCanvas2D;
378
379    /**
380     * Returns an image with the given pixel data and format.
381     * Note that we will always make a copy of the pixel data, because of inconsistencies in
382     * behavior between GPU and CPU (i.e. the pixel data will be turned into a GPU texture and
383     * not modifiable after creation).
384     *
385     * @param info
386     * @param bytes - bytes representing the pixel data.
387     * @param bytesPerRow
388     */
389    MakeImage(info: ImageInfo, bytes: number[] | Uint8Array | Uint8ClampedArray,
390              bytesPerRow: number): Image | null;
391
392    /**
393     * Return an Image backed by the encoded data, but attempt to defer decoding until the image
394     * is actually used/drawn. This deferral allows the system to cache the result, either on the
395     * CPU or on the GPU, depending on where the image is drawn.
396     * This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are
397     * invalid (or an unrecognized codec), null will be returned. See Image.h for more details.
398     * @param bytes
399     */
400    MakeImageFromEncoded(bytes: Uint8Array | ArrayBuffer): Image | null;
401
402    /**
403     * Returns an Image with the data from the provided CanvasImageSource (e.g. <img>). This will
404     * use the browser's built in codecs, in that src will be drawn to a canvas and then readback
405     * and placed into an Image.
406     * @param src
407     */
408    MakeImageFromCanvasImageSource(src: CanvasImageSource): Image;
409
410    /**
411     * Returns an SkPicture which has been serialized previously to the given bytes.
412     * @param bytes
413     */
414    MakePicture(bytes: Uint8Array | ArrayBuffer): SkPicture | null;
415
416    /**
417     * Returns an Vertices based on the given positions and optional parameters.
418     * See SkVertices.h (especially the Builder) for more details.
419     * @param mode
420     * @param positions
421     * @param textureCoordinates
422     * @param colors - either a list of int colors or a flattened color array.
423     * @param indices
424     * @param isVolatile
425     */
426    MakeVertices(mode: VertexMode, positions: InputFlattenedPointArray,
427                 textureCoordinates?: InputFlattenedPointArray | null,
428                 colors?: Float32Array | ColorIntArray | null, indices?: number[] | null,
429                 isVolatile?: boolean): Vertices;
430
431    /**
432     * Returns a Skottie animation built from the provided json string.
433     * Requires that Skottie be compiled into CanvasKit.
434     * @param json
435     */
436    MakeAnimation(json: string): SkottieAnimation;
437
438    /**
439     * Returns a managed Skottie animation built from the provided json string and assets.
440     * Requires that Skottie be compiled into CanvasKit.
441     * @param json
442     * @param assets - a dictionary of named blobs: { key: ArrayBuffer, ... }
443     * @param filterPrefix - an optional string acting as a name filter for selecting "interesting"
444     *                       Lottie properties (surfaced in the embedded player controls)
445     * @param soundMap - an optional mapping of sound identifiers (strings) to AudioPlayers.
446     *                   Only needed if the animation supports sound.
447     */
448    MakeManagedAnimation(json: string, assets?: Record<string, ArrayBuffer>,
449                         filterPrefix?: string, soundMap?: SoundMap): ManagedSkottieAnimation;
450
451    // Constructors, i.e. things made with `new CanvasKit.Foo()`;
452    readonly ImageData: ImageDataConstructor;
453    readonly ParagraphStyle: ParagraphStyleConstructor;
454    readonly ContourMeasureIter: ContourMeasureIterConstructor;
455    readonly Font: FontConstructor;
456    readonly Paint: DefaultConstructor<Paint>;
457    readonly Path: PathConstructorAndFactory;
458    readonly PictureRecorder: DefaultConstructor<PictureRecorder>;
459    readonly TextStyle: TextStyleConstructor;
460
461    // Factories, i.e. things made with CanvasKit.Foo.MakeTurboEncabulator()
462    readonly ParagraphBuilder: ParagraphBuilderFactory;
463    readonly ColorFilter: ColorFilterFactory;
464    readonly FontMgr: FontMgrFactory;
465    readonly ImageFilter: ImageFilterFactory;
466    readonly MaskFilter: MaskFilterFactory;
467    readonly PathEffect: PathEffectFactory;
468    readonly RuntimeEffect: RuntimeEffectFactory;
469    readonly Shader: ShaderFactory;
470    readonly TextBlob: TextBlobFactory;
471    readonly Typeface: TypefaceFactory;
472    readonly TypefaceFontProvider: TypefaceFontProviderFactory;
473
474    // Misc
475    readonly ColorMatrix: ColorMatrixHelpers;
476    readonly Matrix: Matrix3x3Helpers;
477    readonly M44: Matrix4x4Helpers;
478    readonly Vector: VectorHelpers;
479
480    // Core Enums
481    readonly AlphaType: AlphaTypeEnumValues;
482    readonly BlendMode: BlendModeEnumValues;
483    readonly BlurStyle: BlurStyleEnumValues;
484    readonly ClipOp: ClipOpEnumValues;
485    readonly ColorChannel: ColorChannelEnumValues;
486    readonly ColorType: ColorTypeEnumValues;
487    readonly FillType: FillTypeEnumValues;
488    readonly FilterMode: FilterModeEnumValues;
489    readonly FontEdging: FontEdgingEnumValues;
490    readonly FontHinting: FontHintingEnumValues;
491    readonly GlyphRunFlags: GlyphRunFlagValues;
492    readonly ImageFormat: ImageFormatEnumValues;
493    readonly MipmapMode: MipmapModeEnumValues;
494    readonly PaintStyle: PaintStyleEnumValues;
495    readonly Path1DEffect: Path1DEffectStyleEnumValues;
496    readonly PathOp: PathOpEnumValues;
497    readonly PointMode: PointModeEnumValues;
498    readonly ColorSpace: ColorSpaceEnumValues;
499    readonly StrokeCap: StrokeCapEnumValues;
500    readonly StrokeJoin: StrokeJoinEnumValues;
501    readonly TileMode: TileModeEnumValues;
502    readonly VertexMode: VertexModeEnumValues;
503
504    // Core Constants
505    readonly TRANSPARENT: Color;
506    readonly BLACK: Color;
507    readonly WHITE: Color;
508    readonly RED: Color;
509    readonly GREEN: Color;
510    readonly BLUE: Color;
511    readonly YELLOW: Color;
512    readonly CYAN: Color;
513    readonly MAGENTA: Color;
514
515    readonly MOVE_VERB: number;
516    readonly LINE_VERB: number;
517    readonly QUAD_VERB: number;
518    readonly CONIC_VERB: number;
519    readonly CUBIC_VERB: number;
520    readonly CLOSE_VERB: number;
521
522    readonly SaveLayerInitWithPrevious: SaveLayerFlag;
523    readonly SaveLayerF16ColorType: SaveLayerFlag;
524
525    /**
526     * Use this shadow flag to indicate the occluding object is not opaque. Knowing that the
527     * occluder is opaque allows us to cull shadow geometry behind it and improve performance.
528     */
529    readonly ShadowTransparentOccluder: number;
530    /**
531     * Use this shadow flag to not use analytic shadows.
532     */
533    readonly ShadowGeometricOnly: number;
534    /**
535     * Use this shadow flag to indicate the light position represents a direction and light radius
536     * is blur radius at elevation 1.
537     */
538    readonly ShadowDirectionalLight: number;
539
540    readonly gpu?: boolean; // true if GPU code was compiled in
541    readonly managed_skottie?: boolean; // true if advanced (managed) Skottie code was compiled in
542    readonly rt_effect?: boolean; // true if RuntimeEffect was compiled in
543    readonly skottie?: boolean; // true if base Skottie code was compiled in
544
545    // Paragraph Enums
546    readonly Affinity: AffinityEnumValues;
547    readonly DecorationStyle: DecorationStyleEnumValues;
548    readonly FontSlant: FontSlantEnumValues;
549    readonly FontWeight: FontWeightEnumValues;
550    readonly FontWidth: FontWidthEnumValues;
551    readonly PlaceholderAlignment: PlaceholderAlignmentEnumValues;
552    readonly RectHeightStyle: RectHeightStyleEnumValues;
553    readonly RectWidthStyle: RectWidthStyleEnumValues;
554    readonly TextAlign: TextAlignEnumValues;
555    readonly TextBaseline: TextBaselineEnumValues;
556    readonly TextDirection: TextDirectionEnumValues;
557    readonly TextHeightBehavior: TextHeightBehaviorEnumValues;
558
559    // Paragraph Constants
560    readonly NoDecoration: number;
561    readonly UnderlineDecoration: number;
562    readonly OverlineDecoration: number;
563    readonly LineThroughDecoration: number;
564}
565
566export interface Camera {
567    /** a 3d point locating the camera. */
568    eye: Vector3;
569    /** center of attention - the 3d point the camera is looking at. */
570    coa: Vector3;
571    /**
572     * A unit vector pointing the cameras up direction. Note that using only eye and coa
573     * would leave the roll of the camera unspecified.
574     */
575    up: Vector3;
576    /** near clipping plane distance */
577    near: number;
578    /** far clipping plane distance */
579    far: number;
580    /** field of view in radians */
581    angle: AngleInRadians;
582}
583
584/**
585 * CanvasKit is built with Emscripten and Embind. Embind adds the following methods to all objects
586 * that are exposed with it.
587 */
588export interface EmbindObject<T extends EmbindObject<T>> {
589    clone(): T;
590    delete(): void;
591    deleteLater(): void;
592    isAliasOf(other: any): boolean;
593    isDeleted(): boolean;
594}
595
596/**
597 * Represents the set of enum values.
598 */
599export interface EmbindEnum {
600    readonly values: number[];
601}
602
603/**
604 * Represents a single member of an enum.
605 */
606export interface EmbindEnumEntity {
607    readonly value: number;
608}
609
610export interface EmulatedCanvas2D {
611    /**
612     * Cleans up all resources associated with this emulated canvas.
613     */
614    dispose(): void;
615    /**
616     * Decodes an image with the given bytes.
617     * @param bytes
618     */
619    decodeImage(bytes: ArrayBuffer | Uint8Array): Image;
620
621    /**
622     * Returns an emulated canvas2d context if type == '2d', null otherwise.
623     * @param type
624     */
625    getContext(type: string): EmulatedCanvas2DContext | null;
626
627    /**
628     * Loads the given font with the given descriptors. Emulates new FontFace().
629     * @param bytes
630     * @param descriptors
631     */
632    loadFont(bytes: ArrayBuffer | Uint8Array, descriptors: Record<string, string>): void;
633
634    /**
635     * Returns an new emulated Path2D object.
636     * @param str - an SVG string representing a path.
637     */
638    makePath2D(str?: string): EmulatedPath2D;
639
640    /**
641     * Returns the current canvas as a base64 encoded image string.
642     * @param codec - image/png by default; image/jpeg also supported.
643     * @param quality
644     */
645    toDataURL(codec?: string, quality?: number): string;
646}
647
648/** Part of the Canvas2D emulation code */
649export type EmulatedCanvas2DContext = CanvasRenderingContext2D;
650export type EmulatedImageData = ImageData;
651export type EmulatedPath2D = Path2D;
652
653export interface FontStyle {
654    weight?: FontWeight;
655    width?: FontWidth;
656    slant?: FontSlant;
657}
658
659/**
660 * See GrDirectContext.h for more on this class.
661 */
662export interface GrDirectContext extends EmbindObject<GrDirectContext> {
663    getResourceCacheLimitBytes(): number;
664    getResourceCacheUsageBytes(): number;
665    releaseResourcesAndAbandonContext(): void;
666    setResourceCacheLimitBytes(bytes: number): void;
667}
668
669/**
670 * Represents the context backed by a WebGPU device instance.
671 */
672export type WebGPUDeviceContext = GrDirectContext;
673
674/**
675 * Represents the canvas context and swapchain backed by a WebGPU device.
676 */
677export interface WebGPUCanvasContext {
678    /**
679     * A convenient way to draw multiple frames over the swapchain texture sequence associated with
680     * a canvas element. Each call internally constructs a new Surface that targets the current
681     * GPUTexture in swapchain.
682     *
683     * This requires an environment where a global function called requestAnimationFrame is
684     * available (e.g. on the web, not on Node). The internally created surface is flushed and
685     * destroyed automatically by this wrapper once the `drawFrame` callback returns.
686     *
687     * Users can call canvasContext.requestAnimationFrame in the callback function to
688     * draw multiple frames, e.g. of an animation.
689     */
690    requestAnimationFrame(drawFrame: (_: Canvas) => void): void;
691}
692
693/**
694 * See Metrics.h for more on this struct.
695 */
696export interface LineMetrics {
697    /** The index in the text buffer the line begins. */
698    startIndex: number;
699    /** The index in the text buffer the line ends. */
700    endIndex: number;
701    endExcludingWhitespaces: number;
702    endIncludingNewline: number;
703    /** True if the line ends in a hard break (e.g. newline) */
704    isHardBreak: boolean;
705    /**
706     * The final computed ascent for the line. This can be impacted by
707     * the strut, height, scaling, as well as outlying runs that are very tall.
708     */
709    ascent: number;
710    /**
711     * The final computed descent for the line. This can be impacted by
712     * the strut, height, scaling, as well as outlying runs that are very tall.
713     */
714    descent: number;
715    /** round(ascent + descent) */
716    height: number;
717    /** width of the line */
718    width: number;
719    /** The left edge of the line. The right edge can be obtained with `left + width` */
720    left: number;
721    /** The y position of the baseline for this line from the top of the paragraph. */
722    baseline: number;
723    /** Zero indexed line number. */
724    lineNumber: number;
725}
726
727export interface Range {
728    first: number;
729    last: number;
730}
731
732/**
733 * Information for a run of shaped text. See Paragraph.getShapedLines()
734 *
735 * Notes:
736 * positions is documented as Float32, but it holds twice as many as you expect, and they
737 * are treated logically as pairs of floats: {x0, y0}, {x1, y1}, ... for each glyph.
738 *
739 * positions and offsets arrays have 1 extra slot (actually 2 for positions)
740 * to describe the location "after" the last glyph in the glyphs array.
741 */
742export interface GlyphRun {
743    typeface: Typeface;     // currently set to null (temporary)
744    size: number;
745    fakeBold: boolean;
746    fakeItalic: boolean;
747
748    glyphs: Uint16Array;
749    positions: Float32Array;    // alternating x0, y0, x1, y1, ...
750    offsets: Uint32Array;
751    flags: number;              // see GlyphRunFlags
752}
753
754/**
755 * Information for a paragraph of text. See Paragraph.getShapedLines()
756 */
757 export interface ShapedLine {
758    textRange: Range;   // first and last character offsets for the line (derived from runs[])
759    top: number;        // top y-coordinate for the line
760    bottom: number;     // bottom y-coordinate for the line
761    baseline: number;   // baseline y-coordinate for the line
762    runs: GlyphRun[];   // array of GlyphRun objects for the line
763}
764
765/**
766 * Input to ShapeText(..., FontBlock[], ...);
767 */
768export interface FontBlock {
769    length: number;     // number of text codepoints this block is applied to
770
771    typeface: Typeface;
772    size: number;
773    fakeBold: boolean;
774    fakeItalic: boolean;
775}
776
777/**
778 * This object is a wrapper around a pointer to some memory on the WASM heap. The type of the
779 * pointer was determined at creation time.
780 */
781export interface MallocObj {
782    /**
783     * The number of objects this pointer refers to.
784     */
785    readonly length: number;
786    /**
787     * The "pointer" into the WASM memory. Should be fixed over the lifetime of the object.
788     */
789    readonly byteOffset: number;
790    /**
791     * Return a read/write view into a subset of the memory. Do not cache the TypedArray this
792     * returns, it may be invalidated if the WASM heap is resized. This is the same as calling
793     * .toTypedArray().subarray() except the returned TypedArray can also be passed into an API
794     * and not cause an additional copy.
795     */
796    subarray(start: number, end: number): TypedArray;
797    /**
798     * Return a read/write view of the memory. Do not cache the TypedArray this returns, it may be
799     * invalidated if the WASM heap is resized. If this TypedArray is passed into a CanvasKit API,
800     * it will not be copied again, only the pointer will be re-used.
801     */
802    toTypedArray(): TypedArray;
803}
804
805/**
806 * This represents a subset of an animation's duration.
807 */
808export interface AnimationMarker {
809    name: string;
810    t0: number; // 0.0 to 1.0
811    t1: number; // 0.0 to 1.0
812}
813
814/**
815 * This object maintains a single audio layer during skottie playback
816 */
817export interface AudioPlayer {
818    /**
819     * Playback control callback, emitted for each corresponding Animation::seek().
820     *
821     * Will seek to time t (seconds) relative to the layer's timeline origin.
822     * Negative t values are used to signal off state (stop playback outside layer span).
823     */
824    seek(t: number): void;
825}
826
827/**
828 * Mapping of sound names (strings) to AudioPlayers
829 */
830export interface SoundMap {
831    /**
832     * Returns AudioPlayer for a certain audio layer
833     * @param key string identifier, name of audio file the desired AudioPlayer manages
834     */
835    getPlayer(key: string): AudioPlayer;
836}
837
838/**
839 * Named color property.
840 */
841export interface ColorProperty {
842    /**
843     * Property identifier, usually the node name.
844     */
845    key: string;
846    /**
847     * Property value (RGBA, 255-based).
848     */
849    value: ColorInt;
850}
851
852/**
853 * Named opacity property.
854 */
855export interface OpacityProperty {
856    /**
857     * Property identifier, usually the node name.
858     */
859    key: string;
860    /**
861     * Property value (0..100).
862     */
863    value: number;
864}
865
866/**
867 * Text property value.
868 */
869export interface TextValue {
870    /**
871     * The text string payload.
872     */
873    text: string;
874    /**
875     * Font size.
876     */
877    size: number;
878}
879
880/**
881 * Named text property.
882 */
883export interface TextProperty {
884    /**
885     * Property identifier, usually the node name.
886     */
887    key: string;
888    /**
889     * Property value.
890     */
891    value: TextValue;
892}
893
894export interface ManagedSkottieAnimation extends SkottieAnimation {
895    setColor(key: string, color: InputColor): boolean;
896    setOpacity(key: string, opacity: number): boolean;
897    setText(key: string, text: string, size: number): boolean;
898    getMarkers(): AnimationMarker[];
899    getColorProps(): ColorProperty[];
900    getOpacityProps(): OpacityProperty[];
901    getTextProps(): TextProperty[];
902}
903
904/**
905 * See Paragraph.h for more information on this class. This is only available if Paragraph has
906 * been compiled in.
907 */
908export interface Paragraph extends EmbindObject<Paragraph> {
909    didExceedMaxLines(): boolean;
910    getAlphabeticBaseline(): number;
911
912    /**
913     * Returns the index of the glyph that corresponds to the provided coordinate,
914     * with the top left corner as the origin, and +y direction as down.
915     */
916    getGlyphPositionAtCoordinate(dx: number, dy: number): PositionWithAffinity;
917
918    getHeight(): number;
919    getIdeographicBaseline(): number;
920    getLineMetrics(): LineMetrics[];
921    getLongestLine(): number;
922    getMaxIntrinsicWidth(): number;
923    getMaxWidth(): number;
924    getMinIntrinsicWidth(): number;
925    getRectsForPlaceholders(): RectWithDirection[];
926
927    /**
928     * Returns bounding boxes that enclose all text in the range of glpyh indexes [start, end).
929     * @param start
930     * @param end
931     * @param hStyle
932     * @param wStyle
933     */
934    getRectsForRange(start: number, end: number, hStyle: RectHeightStyle,
935                     wStyle: RectWidthStyle): RectWithDirection[];
936
937    /**
938     * Finds the first and last glyphs that define a word containing the glyph at index offset.
939     * @param offset
940     */
941    getWordBoundary(offset: number): URange;
942
943    /**
944     * Returns an array of ShapedLine objects, describing the paragraph.
945     */
946    getShapedLines(): ShapedLine[];
947
948    /**
949     * Lays out the text in the paragraph so it is wrapped to the given width.
950     * @param width
951     */
952    layout(width: number): void;
953}
954
955export interface ParagraphBuilder extends EmbindObject<ParagraphBuilder> {
956    /**
957     * Pushes the information required to leave an open space.
958     * @param width
959     * @param height
960     * @param alignment
961     * @param baseline
962     * @param offset
963     */
964    addPlaceholder(width?: number, height?: number, alignment?: PlaceholderAlignment,
965                   baseline?: TextBaseline, offset?: number): void;
966
967    /**
968     * Adds text to the builder. Forms the proper runs to use the upper-most style
969     * on the style_stack.
970     * @param str
971     */
972    addText(str: string): void;
973
974    /**
975     * Returns a Paragraph object that can be used to be layout and paint the text to an
976     * Canvas.
977     */
978    build(): Paragraph;
979
980    /**
981     * @param words is an array of word edges (starting or ending). You can
982     * pass 2 elements (0 as a start of the entire text and text.size as the
983     * end). This information is only needed for a specific API method getWords.
984     *
985     * The indices are expected to be relative to the UTF-8 representation of
986     * the text.
987     */
988    setWordsUtf8(words: InputWords): void;
989    /**
990     * @param words is an array of word edges (starting or ending). You can
991     * pass 2 elements (0 as a start of the entire text and text.size as the
992     * end). This information is only needed for a specific API method getWords.
993     *
994     * The indices are expected to be relative to the UTF-16 representation of
995     * the text.
996     *
997     * The `Intl.Segmenter` API can be used as a source for this data.
998     */
999    setWordsUtf16(words: InputWords): void;
1000
1001    /**
1002     * @param graphemes is an array of indexes in the input text that point
1003     * to the start of each grapheme.
1004     *
1005     * The indices are expected to be relative to the UTF-8 representation of
1006     * the text.
1007     */
1008    setGraphemeBreaksUtf8(graphemes: InputGraphemes): void;
1009    /**
1010     * @param graphemes is an array of indexes in the input text that point
1011     * to the start of each grapheme.
1012     *
1013     * The indices are expected to be relative to the UTF-16 representation of
1014     * the text.
1015     *
1016     * The `Intl.Segmenter` API can be used as a source for this data.
1017     */
1018    setGraphemeBreaksUtf16(graphemes: InputGraphemes): void;
1019
1020    /**
1021     * @param lineBreaks is an array of unsigned integers that should be
1022     * treated as pairs (index, break type) that point to the places of possible
1023     * line breaking if needed. It should include 0 as the first element.
1024     * Break type == 0 means soft break, break type == 1 is a hard break.
1025     *
1026     * The indices are expected to be relative to the UTF-8 representation of
1027     * the text.
1028     */
1029    setLineBreaksUtf8(lineBreaks: InputLineBreaks): void;
1030    /**
1031     * @param lineBreaks is an array of unsigned integers that should be
1032     * treated as pairs (index, break type) that point to the places of possible
1033     * line breaking if needed. It should include 0 as the first element.
1034     * Break type == 0 means soft break, break type == 1 is a hard break.
1035     *
1036     * The indices are expected to be relative to the UTF-16 representation of
1037     * the text.
1038     *
1039     * Chrome's `v8BreakIterator` API can be used as a source for this data.
1040     */
1041    setLineBreaksUtf16(lineBreaks: InputLineBreaks): void;
1042
1043    /**
1044     * Returns the entire Paragraph text (which is useful in case that text
1045     * was produced as a set of addText calls).
1046     */
1047    getText(): string;
1048
1049    /**
1050     * Remove a style from the stack. Useful to apply different styles to chunks
1051     * of text such as bolding.
1052     */
1053    pop(): void;
1054
1055    /**
1056     * Push a style to the stack. The corresponding text added with addText will
1057     * use the top-most style.
1058     * @param text
1059     */
1060    pushStyle(text: TextStyle): void;
1061
1062    /**
1063     * Pushes a TextStyle using paints instead of colors for foreground and background.
1064     * @param textStyle
1065     * @param fg
1066     * @param bg
1067     */
1068    pushPaintStyle(textStyle: TextStyle, fg: Paint, bg: Paint): void;
1069
1070    /**
1071     * Resets this builder to its initial state, discarding any text, styles, placeholders that have
1072     * been added, but keeping the initial ParagraphStyle.
1073     */
1074    reset(): void;
1075}
1076
1077export interface ParagraphStyle {
1078    disableHinting?: boolean;
1079    ellipsis?: string;
1080    heightMultiplier?: number;
1081    maxLines?: number;
1082    replaceTabCharacters?: boolean;
1083    strutStyle?: StrutStyle;
1084    textAlign?: TextAlign;
1085    textDirection?: TextDirection;
1086    textHeightBehavior?: TextHeightBehavior;
1087    textStyle?: TextStyle;
1088}
1089
1090export interface PositionWithAffinity {
1091    pos: number;
1092    affinity: Affinity;
1093}
1094
1095export interface SkSLUniform {
1096    columns: number;
1097    rows: number;
1098    /** The index into the uniforms array that this uniform begins. */
1099    slot: number;
1100    isInteger: boolean;
1101}
1102
1103/**
1104 * See SkAnimatedImage.h for more information on this class.
1105 */
1106export interface AnimatedImage extends EmbindObject<AnimatedImage> {
1107    /**
1108     * Returns the length of the current frame in ms.
1109     */
1110    currentFrameDuration(): number;
1111    /**
1112     * Decodes the next frame. Returns the length of that new frame in ms.
1113     * Returns -1 when the animation is on the last frame.
1114     */
1115    decodeNextFrame(): number;
1116
1117    /**
1118     * Return the total number of frames in the animation.
1119     */
1120    getFrameCount(): number;
1121
1122    /**
1123     * Return the repetition count for this animation.
1124     */
1125    getRepetitionCount(): number;
1126
1127    /**
1128     * Returns the possibly scaled height of the image.
1129     */
1130    height(): number;
1131
1132    /**
1133     * Returns a still image of the current frame or null if there is no current frame.
1134     */
1135    makeImageAtCurrentFrame(): Image | null;
1136
1137    /**
1138     * Reset the animation to the beginning.
1139     */
1140    reset(): void;
1141
1142    /**
1143     * Returns the possibly scaled width of the image.
1144     */
1145    width(): number;
1146}
1147
1148/**
1149 * See SkCanvas.h for more information on this class.
1150 */
1151export interface Canvas extends EmbindObject<Canvas> {
1152    /**
1153     * Fills the current clip with the given color using Src BlendMode.
1154     * This has the effect of replacing all pixels contained by clip with color.
1155     * @param color
1156     */
1157    clear(color: InputColor): void;
1158
1159    /**
1160     * Replaces clip with the intersection or difference of the current clip and path,
1161     * with an aliased or anti-aliased clip edge.
1162     * @param path
1163     * @param op
1164     * @param doAntiAlias
1165     */
1166    clipPath(path: Path, op: ClipOp, doAntiAlias: boolean): void;
1167
1168    /**
1169     * Replaces clip with the intersection or difference of the current clip and rect,
1170     * with an aliased or anti-aliased clip edge.
1171     * @param rect
1172     * @param op
1173     * @param doAntiAlias
1174     */
1175    clipRect(rect: InputRect, op: ClipOp, doAntiAlias: boolean): void;
1176
1177    /**
1178     * Replaces clip with the intersection or difference of the current clip and rrect,
1179     * with an aliased or anti-aliased clip edge.
1180     * @param rrect
1181     * @param op
1182     * @param doAntiAlias
1183     */
1184    clipRRect(rrect: InputRRect, op: ClipOp, doAntiAlias: boolean): void;
1185
1186    /**
1187     * Replaces current matrix with m premultiplied with the existing matrix.
1188     * @param m
1189     */
1190    concat(m: InputMatrix): void;
1191
1192    /**
1193     * Draws arc using clip, Matrix, and Paint paint.
1194     *
1195     * Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus
1196     * sweepAngle. startAngle and sweepAngle are in degrees.
1197     * @param oval - bounds of oval containing arc to draw
1198     * @param startAngle - angle in degrees where arc begins
1199     * @param sweepAngle - sweep angle in degrees; positive is clockwise
1200     * @param useCenter - if true, include the center of the oval
1201     * @param paint
1202     */
1203    drawArc(oval: InputRect, startAngle: AngleInDegrees, sweepAngle: AngleInDegrees,
1204            useCenter: boolean, paint: Paint): void;
1205
1206    /**
1207     * Draws a set of sprites from atlas, using clip, Matrix, and optional Paint paint.
1208     * @param atlas - Image containing sprites
1209     * @param srcRects - Rect locations of sprites in atlas
1210     * @param dstXforms - RSXform mappings for sprites in atlas
1211     * @param paint
1212     * @param blendMode - BlendMode combining colors and sprites
1213     * @param colors - If provided, will be blended with sprite using blendMode.
1214     * @param sampling - Specifies sampling options. If null, bilinear is used.
1215     */
1216    drawAtlas(atlas: Image, srcRects: InputFlattenedRectangleArray,
1217              dstXforms: InputFlattenedRSXFormArray, paint: Paint,
1218              blendMode?: BlendMode | null, colors?: ColorIntArray | null,
1219              sampling?: CubicResampler | FilterOptions): void;
1220
1221    /**
1222     * Draws a circle at (cx, cy) with the given radius.
1223     * @param cx
1224     * @param cy
1225     * @param radius
1226     * @param paint
1227     */
1228    drawCircle(cx: number, cy: number, radius: number, paint: Paint): void;
1229
1230    /**
1231     * Fills clip with the given color.
1232     * @param color
1233     * @param blendMode - defaults to SrcOver.
1234     */
1235    drawColor(color: InputColor, blendMode?: BlendMode): void;
1236
1237    /**
1238     * Fills clip with the given color.
1239     * @param r - red value (typically from 0 to 1.0).
1240     * @param g - green value (typically from 0 to 1.0).
1241     * @param b - blue value (typically from 0 to 1.0).
1242     * @param a - alpha value, range 0 to 1.0 (1.0 is opaque).
1243     * @param blendMode - defaults to SrcOver.
1244     */
1245    drawColorComponents(r: number, g: number, b: number, a: number, blendMode?: BlendMode): void;
1246
1247    /**
1248     * Fills clip with the given color.
1249     * @param color
1250     * @param blendMode - defaults to SrcOver.
1251     */
1252    drawColorInt(color: ColorInt, blendMode?: BlendMode): void;
1253
1254    /**
1255     * Draws RRect outer and inner using clip, Matrix, and Paint paint.
1256     * outer must contain inner or the drawing is undefined.
1257     * @param outer
1258     * @param inner
1259     * @param paint
1260     */
1261    drawDRRect(outer: InputRRect, inner: InputRRect, paint: Paint): void;
1262
1263    /**
1264     * Draws a run of glyphs, at corresponding positions, in a given font.
1265     * @param glyphs the array of glyph IDs (Uint16TypedArray)
1266     * @param positions the array of x,y floats to position each glyph
1267     * @param x x-coordinate of the origin of the entire run
1268     * @param y y-coordinate of the origin of the entire run
1269     * @param font the font that contains the glyphs
1270     * @param paint
1271     */
1272    drawGlyphs(glyphs: InputGlyphIDArray,
1273               positions: InputFlattenedPointArray,
1274               x: number, y: number,
1275               font: Font, paint: Paint): void;
1276
1277    /**
1278     * Draws the given image with its top-left corner at (left, top) using the current clip,
1279     * the current matrix, and optionally-provided paint.
1280     * @param img
1281     * @param left
1282     * @param top
1283     * @param paint
1284     */
1285    drawImage(img: Image, left: number, top: number, paint?: Paint | null): void;
1286
1287    /**
1288     * Draws the given image with its top-left corner at (left, top) using the current clip,
1289     * the current matrix. It will use the cubic sampling options B and C if necessary.
1290     * @param img
1291     * @param left
1292     * @param top
1293     * @param B - See CubicResampler in SkSamplingOptions.h for more information
1294     * @param C - See CubicResampler in SkSamplingOptions.h for more information
1295     * @param paint
1296     */
1297    drawImageCubic(img: Image, left: number, top: number, B: number, C: number,
1298                   paint?: Paint | null): void;
1299
1300    /**
1301     * Draws the given image with its top-left corner at (left, top) using the current clip,
1302     * the current matrix. It will use the provided sampling options if necessary.
1303     * @param img
1304     * @param left
1305     * @param top
1306     * @param fm - The filter mode.
1307     * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps
1308     *             calculated with makeCopyWithDefaultMipmaps;
1309     * @param paint
1310     */
1311    drawImageOptions(img: Image, left: number, top: number, fm: FilterMode,
1312                     mm: MipmapMode, paint?: Paint | null): void;
1313
1314    /**
1315     *  Draws the provided image stretched proportionally to fit into dst rectangle.
1316     *  The center rectangle divides the image into nine sections: four sides, four corners, and
1317     *  the center.
1318     * @param img
1319     * @param center
1320     * @param dest
1321     * @param filter - what technique to use when sampling the image
1322     * @param paint
1323     */
1324    drawImageNine(img: Image, center: InputIRect, dest: InputRect, filter: FilterMode,
1325                  paint?: Paint | null): void;
1326
1327    /**
1328     * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.
1329     * @param img
1330     * @param src
1331     * @param dest
1332     * @param paint
1333     * @param fastSample - if false, will filter strictly within src.
1334     */
1335    drawImageRect(img: Image, src: InputRect, dest: InputRect, paint: Paint,
1336                  fastSample?: boolean): void;
1337
1338    /**
1339     * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.
1340     * It will use the cubic sampling options B and C if necessary.
1341     * @param img
1342     * @param src
1343     * @param dest
1344     * @param B - See CubicResampler in SkSamplingOptions.h for more information
1345     * @param C - See CubicResampler in SkSamplingOptions.h for more information
1346     * @param paint
1347     */
1348    drawImageRectCubic(img: Image, src: InputRect, dest: InputRect,
1349                       B: number, C: number, paint?: Paint | null): void;
1350
1351    /**
1352     * Draws sub-rectangle src from provided image, scaled and translated to fill dst rectangle.
1353     * It will use the provided sampling options if necessary.
1354     * @param img
1355     * @param src
1356     * @param dest
1357     * @param fm - The filter mode.
1358     * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps
1359     *             calculated with makeCopyWithDefaultMipmaps;
1360     * @param paint
1361     */
1362    drawImageRectOptions(img: Image, src: InputRect, dest: InputRect, fm: FilterMode,
1363                         mm: MipmapMode, paint?: Paint | null): void;
1364
1365    /**
1366     * Draws line segment from (x0, y0) to (x1, y1) using the current clip, current matrix,
1367     * and the provided paint.
1368     * @param x0
1369     * @param y0
1370     * @param x1
1371     * @param y1
1372     * @param paint
1373     */
1374    drawLine(x0: number, y0: number, x1: number, y1: number, paint: Paint): void;
1375
1376    /**
1377     * Draws an oval bounded by the given rectangle using the current clip, current matrix,
1378     * and the provided paint.
1379     * @param oval
1380     * @param paint
1381     */
1382    drawOval(oval: InputRect, paint: Paint): void;
1383
1384    /**
1385     * Fills clip with the given paint.
1386     * @param paint
1387     */
1388    drawPaint(paint: Paint): void;
1389
1390    /**
1391     * Draws the given Paragraph at the provided coordinates.
1392     * Requires the Paragraph code to be compiled in.
1393     * @param p
1394     * @param x
1395     * @param y
1396     */
1397    drawParagraph(p: Paragraph, x: number, y: number): void;
1398
1399    /**
1400     * Draws the given path using the current clip, current matrix, and the provided paint.
1401     * @param path
1402     * @param paint
1403     */
1404    drawPath(path: Path, paint: Paint): void;
1405
1406    /**
1407     * Draws a cubic patch defined by 12 control points [top, right, bottom, left] with optional
1408     * colors and shader-coordinates [4] specifed for each corner [top-left, top-right, bottom-right, bottom-left]
1409     * @param cubics 12 points : 4 connected cubics specifying the boundary of the patch
1410     * @param colors optional colors interpolated across the patch
1411     * @param texs optional shader coordinates interpolated across the patch
1412     * @param mode Specifies how shader and colors blend (if both are specified)
1413     * @param paint
1414     */
1415    drawPatch(cubics: InputFlattenedPointArray,
1416              colors?: ColorIntArray | Color[] | null,
1417              texs?: InputFlattenedPointArray | null,
1418              mode?: BlendMode | null,
1419              paint?: Paint): void;
1420
1421    /**
1422     * Draws the given picture using the current clip, current matrix, and the provided paint.
1423     * @param skp
1424     */
1425    drawPicture(skp: SkPicture): void;
1426
1427    /**
1428     * Draws the given points using the current clip, current matrix, and the provided paint.
1429     *
1430     * See Canvas.h for more on the mode and its interaction with paint.
1431     * @param mode
1432     * @param points
1433     * @param paint
1434     */
1435    drawPoints(mode: PointMode, points: InputFlattenedPointArray, paint: Paint): void;
1436
1437    /**
1438     * Draws the given rectangle using the current clip, current matrix, and the provided paint.
1439     * @param rect
1440     * @param paint
1441     */
1442    drawRect(rect: InputRect, paint: Paint): void;
1443
1444    /**
1445     * Draws the given rectangle using the current clip, current matrix, and the provided paint.
1446     * @param left
1447     * @param top
1448     * @param right
1449     * @param bottom
1450     * @param paint
1451     */
1452    drawRect4f(left: number, top: number, right: number, bottom: number, paint: Paint): void;
1453
1454    /**
1455     * Draws the given rectangle with rounded corners using the current clip, current matrix,
1456     * and the provided paint.
1457     * @param rrect
1458     * @param paint
1459     */
1460    drawRRect(rrect: InputRRect, paint: Paint): void;
1461
1462    /**
1463     * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
1464     * light. See SkShadowUtils.h for more details
1465     * @param path - The occluder used to generate the shadows.
1466     * @param zPlaneParams - Values for the plane function which returns the Z offset of the
1467     *                       occluder from the canvas based on local x and y values (the current
1468     *                       matrix is not applied).
1469     * @param lightPos - The 3D position of the light relative to the canvas plane. This is
1470     *                   independent of the canvas's current matrix.
1471     * @param lightRadius - The radius of the disc light.
1472     * @param ambientColor - The color of the ambient shadow.
1473     * @param spotColor -  The color of the spot shadow.
1474     * @param flags - See SkShadowFlags.h; 0 means use default options.
1475     */
1476    drawShadow(path: Path, zPlaneParams: InputVector3, lightPos: InputVector3, lightRadius: number,
1477               ambientColor: InputColor, spotColor: InputColor, flags: number): void;
1478
1479    /**
1480     * Draw the given text at the location (x, y) using the provided paint and font. The text will
1481     * be drawn as is; no shaping, left-to-right, etc.
1482     * @param str
1483     * @param x
1484     * @param y
1485     * @param paint
1486     * @param font
1487     */
1488    drawText(str: string, x: number, y: number, paint: Paint, font: Font): void;
1489
1490    /**
1491     * Draws the given TextBlob at (x, y) using the current clip, current matrix, and the
1492     * provided paint. Reminder that the fonts used to draw TextBlob are part of the blob.
1493     * @param blob
1494     * @param x
1495     * @param y
1496     * @param paint
1497     */
1498    drawTextBlob(blob: TextBlob, x: number, y: number, paint: Paint): void;
1499
1500    /**
1501     * Draws the given vertices (a triangle mesh) using the current clip, current matrix, and the
1502     * provided paint.
1503     *  If paint contains an Shader and vertices does not contain texCoords, the shader
1504     *  is mapped using the vertices' positions.
1505     *  If vertices colors are defined in vertices, and Paint paint contains Shader,
1506     *  BlendMode mode combines vertices colors with Shader.
1507     * @param verts
1508     * @param mode
1509     * @param paint
1510     */
1511    drawVertices(verts: Vertices, mode: BlendMode, paint: Paint): void;
1512
1513    /**
1514     * Returns the bounds of clip, unaffected by the canvas's matrix.
1515     * If the clip is empty, all four integers in the returned rectangle will equal zero.
1516     *
1517     * @param output - if provided, the results will be copied into the given array instead of
1518     *      allocating a new one.
1519     */
1520    getDeviceClipBounds(output?: IRect): IRect;
1521
1522    /**
1523     * Returns the current transform from local coordinates to the 'device', which for most
1524     * purposes means pixels.
1525     */
1526    getLocalToDevice(): Matrix4x4;
1527
1528    /**
1529     * Returns the number of saved states, each containing: Matrix and clip.
1530     * Equals the number of save() calls less the number of restore() calls plus one.
1531     * The save count of a new canvas is one.
1532     */
1533    getSaveCount(): number;
1534
1535    /**
1536     * Legacy version of getLocalToDevice(), which strips away any Z information, and
1537     * just returns a 3x3 version.
1538     */
1539    getTotalMatrix(): number[];
1540
1541    /**
1542     * Creates Surface matching info and props, and associates it with Canvas.
1543     * Returns null if no match found.
1544     * @param info
1545     */
1546    makeSurface(info: ImageInfo): Surface | null;
1547
1548    /**
1549     * Returns a TypedArray containing the pixels reading starting at (srcX, srcY) and does not
1550     * exceed the size indicated by imageInfo. See SkCanvas.h for more on the caveats.
1551     *
1552     * If dest is not provided, we allocate memory equal to the provided height * the provided
1553     * bytesPerRow to fill the data with.
1554     *
1555     * This is generally a very expensive call for the GPU backend.
1556     *
1557     * @param srcX
1558     * @param srcY
1559     * @param imageInfo - describes the destination format of the pixels.
1560     * @param dest - If provided, the pixels will be copied into the allocated buffer allowing
1561     *        access to the pixels without allocating a new TypedArray.
1562     * @param bytesPerRow - number of bytes per row. Must be provided if dest is set. This
1563     *        depends on destination ColorType. For example, it must be at least 4 * width for
1564     *        the 8888 color type.
1565     * @returns a TypedArray appropriate for the specified ColorType. Note that 16 bit floats are
1566     *          not supported in JS, so that colorType corresponds to raw bytes Uint8Array.
1567     */
1568    readPixels(srcX: number, srcY: number, imageInfo: ImageInfo, dest?: MallocObj,
1569               bytesPerRow?: number): Float32Array | Uint8Array | null;
1570
1571    /**
1572     * Removes changes to the current matrix and clip since Canvas state was
1573     * last saved. The state is removed from the stack.
1574     * Does nothing if the stack is empty.
1575     */
1576    restore(): void;
1577
1578    /**
1579     * Restores state to a previous stack value.
1580     * @param saveCount
1581     */
1582    restoreToCount(saveCount: number): void;
1583
1584    /**
1585     * Rotates the current matrix by the number of degrees.
1586     * @param rot - angle of rotation in degrees.
1587     * @param rx
1588     * @param ry
1589     */
1590    rotate(rot: AngleInDegrees, rx: number, ry: number): void;
1591
1592    /**
1593     * Saves the current matrix and clip and returns current height of the stack.
1594     */
1595    save(): number;
1596
1597    /**
1598     * Saves Matrix and clip, and allocates a SkBitmap for subsequent drawing.
1599     * Calling restore() discards changes to Matrix and clip, and draws the SkBitmap.
1600     * It returns the height of the stack.
1601     * See Canvas.h for more.
1602     * @param paint
1603     * @param bounds
1604     * @param backdrop
1605     * @param flags
1606     */
1607    saveLayer(paint?: Paint, bounds?: InputRect | null, backdrop?: ImageFilter | null,
1608              flags?: SaveLayerFlag): number;
1609
1610    /**
1611     * Scales the current matrix by sx on the x-axis and sy on the y-axis.
1612     * @param sx
1613     * @param sy
1614     */
1615    scale(sx: number, sy: number): void;
1616
1617    /**
1618     *  Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx
1619     *  skews the drawing right as y-axis values increase; a positive value of sy skews
1620     *  the drawing down as x-axis values increase.
1621     * @param sx
1622     * @param sy
1623     */
1624    skew(sx: number, sy: number): void;
1625
1626    /**
1627     * Translates Matrix by dx along the x-axis and dy along the y-axis.
1628     * @param dx
1629     * @param dy
1630     */
1631    translate(dx: number, dy: number): void;
1632
1633    /**
1634     * Writes the given rectangle of pixels to the provided coordinates. The source pixels
1635     * will be converted to the canvas's alphaType and colorType if they do not match.
1636     * @param pixels
1637     * @param srcWidth
1638     * @param srcHeight
1639     * @param destX
1640     * @param destY
1641     * @param alphaType - defaults to Unpremul
1642     * @param colorType - defaults to RGBA_8888
1643     * @param colorSpace - defaults to SRGB
1644     */
1645    writePixels(pixels: Uint8Array | number[], srcWidth: number, srcHeight: number,
1646                destX: number, destY: number, alphaType?: AlphaType, colorType?: ColorType,
1647                colorSpace?: ColorSpace): boolean;
1648}
1649
1650/**
1651 * See SkColorFilter.h for more on this class. The objects are opaque.
1652 */
1653export type ColorFilter = EmbindObject<ColorFilter>;
1654
1655export interface ContourMeasureIter extends EmbindObject<ContourMeasureIter> {
1656    /**
1657     *  Iterates through contours in path, returning a contour-measure object for each contour
1658     *  in the path. Returns null when it is done.
1659     *
1660     *  See SkContourMeasure.h for more details.
1661     */
1662    next(): ContourMeasure | null;
1663}
1664
1665export interface ContourMeasure extends EmbindObject<ContourMeasure> {
1666    /**
1667     * Returns the given position and tangent line for the distance on the given contour.
1668     * The return value is 4 floats in this order: posX, posY, vecX, vecY.
1669     * @param distance - will be pinned between 0 and length().
1670     * @param output - if provided, the four floats of the PosTan will be copied into this array
1671     *                 instead of allocating a new one.
1672     */
1673    getPosTan(distance: number, output?: PosTan): PosTan;
1674
1675    /**
1676     * Returns an Path representing the segement of this contour.
1677     * @param startD - will be pinned between 0 and length()
1678     * @param stopD - will be pinned between 0 and length()
1679     * @param startWithMoveTo
1680     */
1681    getSegment(startD: number, stopD: number, startWithMoveTo: boolean): Path;
1682
1683    /**
1684     * Returns true if the contour is closed.
1685     */
1686    isClosed(): boolean;
1687
1688    /**
1689     * Returns the length of this contour.
1690     */
1691    length(): number;
1692}
1693
1694export interface FontMetrics {
1695    ascent: number;     // suggested space above the baseline. < 0
1696    descent: number;    // suggested space below the baseline. > 0
1697    leading: number;    // suggested spacing between descent of previous line and ascent of next line.
1698    bounds?: Rect;      // smallest rect containing all glyphs (relative to 0,0)
1699}
1700
1701/**
1702 * See SkFont.h for more on this class.
1703 */
1704export interface Font extends EmbindObject<Font> {
1705    /**
1706     * Returns the FontMetrics for this font.
1707     */
1708    getMetrics(): FontMetrics;
1709
1710    /**
1711     * Retrieves the bounds for each glyph in glyphs.
1712     * If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
1713     * These are returned as flattened rectangles.  For each glyph, there will be 4 floats for
1714     * left, top, right, bottom (relative to 0, 0) for that glyph.
1715     * @param glyphs
1716     * @param paint
1717     * @param output - if provided, the results will be copied into this array.
1718     */
1719    getGlyphBounds(glyphs: InputGlyphIDArray, paint?: Paint | null,
1720                   output?: Float32Array): Float32Array;
1721
1722    /**
1723     * Retrieves the glyph ids for each code point in the provided string. This call is passed to
1724     * the typeface of this font. Note that glyph IDs are typeface-dependent; different faces
1725     * may have different ids for the same code point.
1726     * @param str
1727     * @param numCodePoints - the number of code points in the string. Defaults to str.length.
1728     * @param output - if provided, the results will be copied into this array.
1729     */
1730    getGlyphIDs(str: string, numCodePoints?: number,
1731                output?: GlyphIDArray): GlyphIDArray;
1732
1733    /**
1734     * Retrieves the advanceX measurements for each glyph.
1735     * If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
1736     * One width per glyph is returned in the returned array.
1737     * @param glyphs
1738     * @param paint
1739     * @param output - if provided, the results will be copied into this array.
1740     */
1741    getGlyphWidths(glyphs: InputGlyphIDArray, paint?: Paint | null,
1742                   output?: Float32Array): Float32Array;
1743
1744    /**
1745     * Computes any intersections of a thick "line" and a run of positionsed glyphs.
1746     * The thick line is represented as a top and bottom coordinate (positive for
1747     * below the baseline, negative for above). If there are no intersections
1748     * (e.g. if this is intended as an underline, and there are no "collisions")
1749     * then the returned array will be empty. If there are intersections, the array
1750     * will contain pairs of X coordinates [start, end] for each segment that
1751     * intersected with a glyph.
1752     *
1753     * @param glyphs        the glyphs to intersect with
1754     * @param positions     x,y coordinates (2 per glyph) for each glyph
1755     * @param top           top of the thick "line" to use for intersection testing
1756     * @param bottom        bottom of the thick "line" to use for intersection testing
1757     * @return              array of [start, end] x-coordinate pairs. Maybe be empty.
1758     */
1759    getGlyphIntercepts(glyphs: InputGlyphIDArray, positions: Float32Array | number[],
1760                       top: number, bottom: number): Float32Array;
1761
1762    /**
1763     * Returns text scale on x-axis. Default value is 1.
1764     */
1765    getScaleX(): number;
1766
1767    /**
1768     * Returns text size in points.
1769     */
1770    getSize(): number;
1771
1772    /**
1773     * Returns text skew on x-axis. Default value is zero.
1774     */
1775    getSkewX(): number;
1776
1777    /**
1778     * Returns embolden effect for this font. Default value is false.
1779     */
1780    isEmbolden(): boolean;
1781
1782    /**
1783     * Returns the Typeface set for this font.
1784     */
1785    getTypeface(): Typeface | null;
1786
1787    /**
1788     * Requests, but does not require, that edge pixels draw opaque or with partial transparency.
1789     * @param edging
1790     */
1791    setEdging(edging: FontEdging): void;
1792
1793    /**
1794     * Requests, but does not require, to use bitmaps in fonts instead of outlines.
1795     * @param embeddedBitmaps
1796     */
1797    setEmbeddedBitmaps(embeddedBitmaps: boolean): void;
1798
1799    /**
1800     * Sets level of glyph outline adjustment.
1801     * @param hinting
1802     */
1803    setHinting(hinting: FontHinting): void;
1804
1805    /**
1806     * Requests, but does not require, linearly scalable font and glyph metrics.
1807     *
1808     * For outline fonts 'true' means font and glyph metrics should ignore hinting and rounding.
1809     * Note that some bitmap formats may not be able to scale linearly and will ignore this flag.
1810     * @param linearMetrics
1811     */
1812    setLinearMetrics(linearMetrics: boolean): void;
1813
1814    /**
1815     * Sets the text scale on the x-axis.
1816     * @param sx
1817     */
1818    setScaleX(sx: number): void;
1819
1820    /**
1821     * Sets the text size in points on this font.
1822     * @param points
1823     */
1824    setSize(points: number): void;
1825
1826    /**
1827     * Sets the text-skew on the x axis for this font.
1828     * @param sx
1829     */
1830    setSkewX(sx: number): void;
1831
1832    /**
1833     * Set embolden effect for this font.
1834     * @param embolden
1835     */
1836    setEmbolden(embolden: boolean): void;
1837
1838    /**
1839     * Requests, but does not require, that glyphs respect sub-pixel positioning.
1840     * @param subpixel
1841     */
1842    setSubpixel(subpixel: boolean): void;
1843
1844    /**
1845     * Sets the typeface to use with this font. null means to clear the typeface and use the
1846     * default one.
1847     * @param face
1848     */
1849    setTypeface(face: Typeface | null): void;
1850}
1851
1852/**
1853 * See SkFontMgr.h for more details
1854 */
1855export interface FontMgr extends EmbindObject<FontMgr> {
1856    /**
1857     * Return the number of font families loaded in this manager. Useful for debugging.
1858     */
1859    countFamilies(): number;
1860
1861    /**
1862     * Return the nth family name. Useful for debugging.
1863     * @param index
1864     */
1865    getFamilyName(index: number): string;
1866}
1867
1868/**
1869 * See SkImage.h for more information on this class.
1870 */
1871export interface Image extends EmbindObject<Image> {
1872    /**
1873     * Encodes this image's pixels to the specified format and returns them. Must be built with
1874     * the specified codec. If the options are unspecified, sensible defaults will be
1875     * chosen.
1876     * @param fmt - PNG is the default value.
1877     * @param quality - a value from 0 to 100; 100 is the least lossy. May be ignored.
1878     */
1879    encodeToBytes(fmt?: EncodedImageFormat, quality?: number): Uint8Array | null;
1880
1881    /**
1882     * Returns the color space associated with this object.
1883     * It is the user's responsibility to call delete() on this after it has been used.
1884     */
1885    getColorSpace(): ColorSpace;
1886
1887    /**
1888     * Returns the width, height, colorType and alphaType associated with this image.
1889     * Colorspace is separate so as to not accidentally leak that memory.
1890     */
1891    getImageInfo(): PartialImageInfo;
1892
1893    /**
1894     * Return the height in pixels of the image.
1895     */
1896    height(): number;
1897
1898    /**
1899     * Returns an Image with the same "base" pixels as the this image, but with mipmap levels
1900     * automatically generated and attached.
1901     */
1902    makeCopyWithDefaultMipmaps(): Image;
1903
1904    /**
1905     * Returns this image as a shader with the specified tiling. It will use cubic sampling.
1906     * @param tx - tile mode in the x direction.
1907     * @param ty - tile mode in the y direction.
1908     * @param B - See CubicResampler in SkSamplingOptions.h for more information
1909     * @param C - See CubicResampler in SkSamplingOptions.h for more information
1910     * @param localMatrix
1911     */
1912    makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number,
1913                    localMatrix?: InputMatrix): Shader;
1914
1915    /**
1916     * Returns this image as a shader with the specified tiling. It will use cubic sampling.
1917     * @param tx - tile mode in the x direction.
1918     * @param ty - tile mode in the y direction.
1919     * @param fm - The filter mode.
1920     * @param mm - The mipmap mode. Note: for settings other than None, the image must have mipmaps
1921     *             calculated with makeCopyWithDefaultMipmaps;
1922     * @param localMatrix
1923     */
1924    makeShaderOptions(tx: TileMode, ty: TileMode, fm: FilterMode, mm: MipmapMode,
1925                    localMatrix?: InputMatrix): Shader;
1926
1927    /**
1928     * Returns a TypedArray containing the pixels reading starting at (srcX, srcY) and does not
1929     * exceed the size indicated by imageInfo. See SkImage.h for more on the caveats.
1930     *
1931     * If dest is not provided, we allocate memory equal to the provided height * the provided
1932     * bytesPerRow to fill the data with.
1933     *
1934     * @param srcX
1935     * @param srcY
1936     * @param imageInfo - describes the destination format of the pixels.
1937     * @param dest - If provided, the pixels will be copied into the allocated buffer allowing
1938     *        access to the pixels without allocating a new TypedArray.
1939     * @param bytesPerRow - number of bytes per row. Must be provided if dest is set. This
1940     *        depends on destination ColorType. For example, it must be at least 4 * width for
1941     *        the 8888 color type.
1942     * @returns a TypedArray appropriate for the specified ColorType. Note that 16 bit floats are
1943     *          not supported in JS, so that colorType corresponds to raw bytes Uint8Array.
1944     */
1945    readPixels(srcX: number, srcY: number, imageInfo: ImageInfo, dest?: MallocObj,
1946               bytesPerRow?: number): Float32Array | Uint8Array | null;
1947
1948    /**
1949     * Return the width in pixels of the image.
1950     */
1951    width(): number;
1952}
1953
1954/**
1955 * See ImageFilter.h for more on this class. The objects are opaque.
1956 */
1957export type ImageFilter = EmbindObject<ImageFilter>;
1958
1959export interface ImageInfo {
1960    alphaType: AlphaType;
1961    colorSpace: ColorSpace;
1962    colorType: ColorType;
1963    height: number;
1964    width: number;
1965}
1966
1967export interface PartialImageInfo {
1968    alphaType: AlphaType;
1969    colorType: ColorType;
1970    height: number;
1971    width: number;
1972}
1973
1974/*
1975 *  Specifies sampling with bicubic coefficients
1976 */
1977export interface CubicResampler {
1978    B: number;  // 0..1
1979    C: number;  // 0..1
1980}
1981
1982/**
1983 * Specifies sampling using filter and mipmap options
1984 */
1985export interface FilterOptions {
1986    filter: FilterMode;
1987    mipmap?: MipmapMode;    // defaults to None if not specified
1988}
1989
1990/**
1991 * See SkMaskFilter.h for more on this class. The objects are opaque.
1992 */
1993export type MaskFilter = EmbindObject<MaskFilter>;
1994
1995/**
1996 * See SkPaint.h for more information on this class.
1997 */
1998export interface Paint extends EmbindObject<Paint> {
1999    /**
2000     * Returns a copy of this paint.
2001     */
2002    copy(): Paint;
2003
2004    /**
2005     * Retrieves the alpha and RGB unpremultiplied. RGB are extended sRGB values
2006     * (sRGB gamut, and encoded with the sRGB transfer function).
2007     */
2008    getColor(): Color;
2009
2010    /**
2011     * Returns the geometry drawn at the beginning and end of strokes.
2012     */
2013    getStrokeCap(): StrokeCap;
2014
2015    /**
2016     * Returns the geometry drawn at the corners of strokes.
2017     */
2018    getStrokeJoin(): StrokeJoin;
2019
2020    /**
2021     *  Returns the limit at which a sharp corner is drawn beveled.
2022     */
2023    getStrokeMiter(): number;
2024
2025    /**
2026     * Returns the thickness of the pen used to outline the shape.
2027     */
2028    getStrokeWidth(): number;
2029
2030    /**
2031     * Replaces alpha, leaving RGBA unchanged. 0 means fully transparent, 1.0 means opaque.
2032     * @param alpha
2033     */
2034    setAlphaf(alpha: number): void;
2035
2036    /**
2037     * Requests, but does not require, that edge pixels draw opaque or with
2038     * partial transparency.
2039     * @param aa
2040     */
2041    setAntiAlias(aa: boolean): void;
2042
2043    /**
2044     * Sets the blend mode that is, the mode used to combine source color
2045     * with destination color.
2046     * @param mode
2047     */
2048    setBlendMode(mode: BlendMode): void;
2049
2050    /**
2051     * Sets alpha and RGB used when stroking and filling. The color is four floating
2052     * point values, unpremultiplied. The color values are interpreted as being in
2053     * the provided colorSpace.
2054     * @param color
2055     * @param colorSpace - defaults to sRGB
2056     */
2057    setColor(color: InputColor, colorSpace?: ColorSpace): void;
2058
2059    /**
2060     * Sets alpha and RGB used when stroking and filling. The color is four floating
2061     * point values, unpremultiplied. The color values are interpreted as being in
2062     * the provided colorSpace.
2063     * @param r
2064     * @param g
2065     * @param b
2066     * @param a
2067     * @param colorSpace - defaults to sRGB
2068     */
2069    setColorComponents(r: number, g: number, b: number, a: number, colorSpace?: ColorSpace): void;
2070
2071    /**
2072     * Sets the current color filter, replacing the existing one if there was one.
2073     * @param filter
2074     */
2075    setColorFilter(filter: ColorFilter | null): void;
2076
2077    /**
2078     * Sets the color used when stroking and filling. The color values are interpreted as being in
2079     * the provided colorSpace.
2080     * @param color
2081     * @param colorSpace - defaults to sRGB.
2082     */
2083    setColorInt(color: ColorInt, colorSpace?: ColorSpace): void;
2084
2085    /**
2086     * Sets the current image filter, replacing the existing one if there was one.
2087     * @param filter
2088     */
2089    setImageFilter(filter: ImageFilter | null): void;
2090
2091    /**
2092     * Sets the current mask filter, replacing the existing one if there was one.
2093     * @param filter
2094     */
2095    setMaskFilter(filter: MaskFilter | null): void;
2096
2097    /**
2098     * Sets the current path effect, replacing the existing one if there was one.
2099     * @param effect
2100     */
2101    setPathEffect(effect: PathEffect | null): void;
2102
2103    /**
2104     * Sets the current shader, replacing the existing one if there was one.
2105     * @param shader
2106     */
2107    setShader(shader: Shader | null): void;
2108
2109    /**
2110     * Sets the geometry drawn at the beginning and end of strokes.
2111     * @param cap
2112     */
2113    setStrokeCap(cap: StrokeCap): void;
2114
2115    /**
2116     * Sets the geometry drawn at the corners of strokes.
2117     * @param join
2118     */
2119    setStrokeJoin(join: StrokeJoin): void;
2120
2121    /**
2122     * Sets the limit at which a sharp corner is drawn beveled.
2123     * @param limit
2124     */
2125    setStrokeMiter(limit: number): void;
2126
2127    /**
2128     * Sets the thickness of the pen used to outline the shape.
2129     * @param width
2130     */
2131    setStrokeWidth(width: number): void;
2132
2133    /**
2134     * Sets whether the geometry is filled or stroked.
2135     * @param style
2136     */
2137    setStyle(style: PaintStyle): void;
2138}
2139
2140/**
2141 * See SkPath.h for more information on this class.
2142 */
2143export interface Path extends EmbindObject<Path> {
2144    /**
2145     * Appends arc to Path, as the start of new contour. Arc added is part of ellipse
2146     * bounded by oval, from startAngle through sweepAngle. Both startAngle and
2147     * sweepAngle are measured in degrees, where zero degrees is aligned with the
2148     * positive x-axis, and positive sweeps extends arc clockwise.
2149     * Returns the modified path for easier chaining.
2150     * @param oval
2151     * @param startAngle
2152     * @param sweepAngle
2153     */
2154    addArc(oval: InputRect, startAngle: AngleInDegrees, sweepAngle: AngleInDegrees): Path;
2155
2156    /**
2157     * Adds circle centered at (x, y) of size radius to the path.
2158     * Has no effect if radius is zero or negative.
2159     *
2160     * @param x       center of circle
2161     * @param y       center of circle
2162     * @param radius  distance from center to edge
2163     * @param isCCW - if the path should be drawn counter-clockwise or not
2164     * @return        reference to SkPath
2165     */
2166    addCircle(x: number, y: number, r: number, isCCW?: boolean): Path;
2167
2168    /**
2169     * Adds oval to Path, appending kMove_Verb, four kConic_Verb, and kClose_Verb.
2170     * Oval is upright ellipse bounded by Rect oval with radii equal to half oval width
2171     * and half oval height. Oval begins at start and continues clockwise by default.
2172     * Returns the modified path for easier chaining.
2173     * @param oval
2174     * @param isCCW - if the path should be drawn counter-clockwise or not
2175     * @param startIndex - index of initial point of ellipse
2176     */
2177    addOval(oval: InputRect, isCCW?: boolean, startIndex?: number): Path;
2178
2179    /**
2180     * Takes 1, 2, 7, or 10 required args, where the first arg is always the path.
2181     * The last arg is an optional boolean and chooses between add or extend mode.
2182     * The options for the remaining args are:
2183     *   - an array of 6 or 9 parameters (perspective is optional)
2184     *   - the 9 parameters of a full matrix or
2185     *     the 6 non-perspective params of a matrix.
2186     * Returns the modified path for easier chaining (or null if params were incorrect).
2187     * @param args
2188     */
2189    addPath(...args: any[]): Path | null;
2190
2191    /**
2192     * Adds contour created from array of n points, adding (count - 1) line segments.
2193     * Contour added starts at pts[0], then adds a line for every additional point
2194     * in pts array. If close is true, appends kClose_Verb to Path, connecting
2195     * pts[count - 1] and pts[0].
2196     * Returns the modified path for easier chaining.
2197     * @param points
2198     * @param close - if true, will add a line connecting last point to the first point.
2199     */
2200    addPoly(points: InputFlattenedPointArray, close: boolean): Path;
2201
2202    /**
2203     * Adds Rect to Path, appending kMove_Verb, three kLine_Verb, and kClose_Verb,
2204     * starting with top-left corner of Rect; followed by top-right, bottom-right,
2205     * and bottom-left if isCCW is false; or followed by bottom-left,
2206     * bottom-right, and top-right if isCCW is true.
2207     * Returns the modified path for easier chaining.
2208     * @param rect
2209     * @param isCCW
2210     */
2211    addRect(rect: InputRect, isCCW?: boolean): Path;
2212
2213    /**
2214     * Adds rrect to Path, creating a new closed contour.
2215     * Returns the modified path for easier chaining.
2216     * @param rrect
2217     * @param isCCW
2218     */
2219    addRRect(rrect: InputRRect, isCCW?: boolean): Path;
2220
2221    /**
2222     * Adds the given verbs and associated points/weights to the path. The process
2223     * reads the first verb from verbs and then the appropriate number of points from the
2224     * FlattenedPointArray (e.g. 2 points for moveTo, 4 points for quadTo, etc). If the verb is
2225     * a conic, a weight will be read from the WeightList.
2226     * Returns the modified path for easier chaining
2227     * @param verbs - the verbs that create this path, in the order of being drawn.
2228     * @param points - represents n points with 2n floats.
2229     * @param weights - used if any of the verbs are conics, can be omitted otherwise.
2230     */
2231    addVerbsPointsWeights(verbs: VerbList, points: InputFlattenedPointArray,
2232                          weights?: WeightList): Path;
2233
2234    /**
2235     * Adds an arc to this path, emulating the Canvas2D behavior.
2236     * Returns the modified path for easier chaining.
2237     * @param x
2238     * @param y
2239     * @param radius
2240     * @param startAngle
2241     * @param endAngle
2242     * @param isCCW
2243     */
2244    arc(x: number, y: number, radius: number, startAngle: AngleInRadians, endAngle: AngleInRadians,
2245        isCCW?: boolean): Path;
2246
2247    /**
2248     * Appends arc to Path. Arc added is part of ellipse
2249     * bounded by oval, from startAngle through sweepAngle. Both startAngle and
2250     * sweepAngle are measured in degrees, where zero degrees is aligned with the
2251     * positive x-axis, and positive sweeps extends arc clockwise.
2252     * Returns the modified path for easier chaining.
2253     * @param oval
2254     * @param startAngle
2255     * @param endAngle
2256     * @param forceMoveTo
2257     */
2258    arcToOval(oval: InputRect, startAngle: AngleInDegrees, endAngle: AngleInDegrees,
2259              forceMoveTo: boolean): Path;
2260
2261    /**
2262     * Appends arc to Path. Arc is implemented by one or more conics weighted to
2263     * describe part of oval with radii (rx, ry) rotated by xAxisRotate degrees. Arc
2264     * curves from last Path Point to (x, y), choosing one of four possible routes:
2265     * clockwise or counterclockwise, and smaller or larger. See SkPath.h for more details.
2266     * Returns the modified path for easier chaining.
2267     * @param rx
2268     * @param ry
2269     * @param xAxisRotate
2270     * @param useSmallArc
2271     * @param isCCW
2272     * @param x
2273     * @param y
2274     */
2275    arcToRotated(rx: number, ry: number, xAxisRotate: AngleInDegrees, useSmallArc: boolean,
2276                 isCCW: boolean, x: number, y: number): Path;
2277
2278    /**
2279     * Appends arc to Path, after appending line if needed. Arc is implemented by conic
2280     * weighted to describe part of circle. Arc is contained by tangent from
2281     * last Path point to (x1, y1), and tangent from (x1, y1) to (x2, y2). Arc
2282     * is part of circle sized to radius, positioned so it touches both tangent lines.
2283     * Returns the modified path for easier chaining.
2284     * @param x1
2285     * @param y1
2286     * @param x2
2287     * @param y2
2288     * @param radius
2289     */
2290    arcToTangent(x1: number, y1: number, x2: number, y2: number, radius: number): Path;
2291
2292    /**
2293     * Appends CLOSE_VERB to Path. A closed contour connects the first and last point
2294     * with a line, forming a continuous loop.
2295     * Returns the modified path for easier chaining.
2296     */
2297    close(): Path;
2298
2299    /**
2300     * Returns minimum and maximum axes values of the lines and curves in Path.
2301     * Returns (0, 0, 0, 0) if Path contains no points.
2302     * Returned bounds width and height may be larger or smaller than area affected
2303     * when Path is drawn.
2304     *
2305     * Behaves identically to getBounds() when Path contains
2306     * only lines. If Path contains curves, computed bounds includes
2307     * the maximum extent of the quad, conic, or cubic; is slower than getBounds();
2308     * and unlike getBounds(), does not cache the result.
2309     * @param outputArray - if provided, the bounding box will be copied into this array instead of
2310     *                      allocating a new one.
2311     */
2312    computeTightBounds(outputArray?: Rect): Rect;
2313
2314    /**
2315     * Adds conic from last point towards (x1, y1), to (x2, y2), weighted by w.
2316     * If Path is empty, or path is closed, the last point is set to (0, 0)
2317     * before adding conic.
2318     * Returns the modified path for easier chaining.
2319     * @param x1
2320     * @param y1
2321     * @param x2
2322     * @param y2
2323     * @param w
2324     */
2325    conicTo(x1: number, y1: number, x2: number, y2: number, w: number): Path;
2326
2327    /**
2328     * Returns true if the point (x, y) is contained by Path, taking into
2329     * account FillType.
2330     * @param x
2331     * @param y
2332     */
2333    contains(x: number, y: number): boolean;
2334
2335    /**
2336     * Returns a copy of this Path.
2337     */
2338    copy(): Path;
2339
2340    /**
2341     * Returns the number of points in this path. Initially zero.
2342     */
2343    countPoints(): number;
2344
2345    /**
2346     *  Adds cubic from last point towards (x1, y1), then towards (x2, y2), ending at
2347     * (x3, y3). If Path is empty, or path is closed, the last point is set to
2348     * (0, 0) before adding cubic.
2349     * @param cpx1
2350     * @param cpy1
2351     * @param cpx2
2352     * @param cpy2
2353     * @param x
2354     * @param y
2355     */
2356    cubicTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number): Path;
2357
2358    /**
2359     * Changes this path to be the dashed version of itself. This is the same effect as creating
2360     * a DashPathEffect and calling filterPath on this path.
2361     * @param on
2362     * @param off
2363     * @param phase
2364     */
2365    dash(on: number, off: number, phase: number): boolean;
2366
2367    /**
2368     * Returns true if other path is equal to this path.
2369     * @param other
2370     */
2371    equals(other: Path): boolean;
2372
2373    /**
2374     * Returns minimum and maximum axes values of Point array.
2375     * Returns (0, 0, 0, 0) if Path contains no points. Returned bounds width and height may
2376     * be larger or smaller than area affected when Path is drawn.
2377     * @param outputArray - if provided, the bounding box will be copied into this array instead of
2378     *                      allocating a new one.
2379     */
2380    getBounds(outputArray?: Rect): Rect;
2381
2382    /**
2383     * Return the FillType for this path.
2384     */
2385    getFillType(): FillType;
2386
2387    /**
2388     * Returns the Point at index in Point array. Valid range for index is
2389     * 0 to countPoints() - 1.
2390     * @param index
2391     * @param outputArray - if provided, the point will be copied into this array instead of
2392     *                      allocating a new one.
2393     */
2394    getPoint(index: number, outputArray?: Point): Point;
2395
2396    /**
2397     * Returns true if there are no verbs in the path.
2398     */
2399    isEmpty(): boolean;
2400
2401    /**
2402     * Returns true if the path is volatile; it will not be altered or discarded
2403     * by the caller after it is drawn. Path by default have volatile set false, allowing
2404     * Surface to attach a cache of data which speeds repeated drawing. If true, Surface
2405     * may not speed repeated drawing.
2406     */
2407    isVolatile(): boolean;
2408
2409    /**
2410     * Adds line from last point to (x, y). If Path is empty, or last path is closed,
2411     * last point is set to (0, 0) before adding line.
2412     * Returns the modified path for easier chaining.
2413     * @param x
2414     * @param y
2415     */
2416    lineTo(x: number, y: number): Path;
2417
2418    /**
2419     * Returns a new path that covers the same area as the original path, but with the
2420     * Winding FillType. This may re-draw some contours in the path as counter-clockwise
2421     * instead of clockwise to achieve that effect. If such a transformation cannot
2422     * be done, null is returned.
2423     */
2424    makeAsWinding(): Path | null;
2425
2426    /**
2427     * Adds beginning of contour at the given point.
2428     * Returns the modified path for easier chaining.
2429     * @param x
2430     * @param y
2431     */
2432    moveTo(x: number, y: number): Path;
2433
2434    /**
2435     * Translates all the points in the path by dx, dy.
2436     * Returns the modified path for easier chaining.
2437     * @param dx
2438     * @param dy
2439     */
2440    offset(dx: number, dy: number): Path;
2441
2442    /**
2443     * Combines this path with the other path using the given PathOp. Returns false if the operation
2444     * fails.
2445     * @param other
2446     * @param op
2447     */
2448    op(other: Path, op: PathOp): boolean;
2449
2450    /**
2451     * Adds quad from last point towards (x1, y1), to (x2, y2).
2452     * If Path is empty, or path is closed, last point is set to (0, 0) before adding quad.
2453     * Returns the modified path for easier chaining.
2454     * @param x1
2455     * @param y1
2456     * @param x2
2457     * @param y2
2458     */
2459    quadTo(x1: number, y1: number, x2: number, y2: number): Path;
2460
2461    /**
2462     * Relative version of arcToRotated.
2463     * @param rx
2464     * @param ry
2465     * @param xAxisRotate
2466     * @param useSmallArc
2467     * @param isCCW
2468     * @param dx
2469     * @param dy
2470     */
2471    rArcTo(rx: number, ry: number, xAxisRotate: AngleInDegrees, useSmallArc: boolean,
2472           isCCW: boolean, dx: number, dy: number): Path;
2473
2474    /**
2475     * Relative version of conicTo.
2476     * @param dx1
2477     * @param dy1
2478     * @param dx2
2479     * @param dy2
2480     * @param w
2481     */
2482    rConicTo(dx1: number, dy1: number, dx2: number, dy2: number, w: number): Path;
2483
2484    /**
2485     * Relative version of cubicTo.
2486     * @param cpx1
2487     * @param cpy1
2488     * @param cpx2
2489     * @param cpy2
2490     * @param x
2491     * @param y
2492     */
2493    rCubicTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number): Path;
2494
2495    /**
2496     * Sets Path to its initial state.
2497     * Removes verb array, point array, and weights, and sets FillType to Winding.
2498     * Internal storage associated with Path is released
2499     */
2500    reset(): void;
2501
2502    /**
2503     * Sets Path to its initial state.
2504     * Removes verb array, point array, and weights, and sets FillType to Winding.
2505     * Internal storage associated with Path is *not* released.
2506     * Use rewind() instead of reset() if Path storage will be reused and performance
2507     * is critical.
2508     */
2509    rewind(): void;
2510
2511    /**
2512     * Relative version of lineTo.
2513     * @param x
2514     * @param y
2515     */
2516    rLineTo(x: number, y: number): Path;
2517
2518    /**
2519     * Relative version of moveTo.
2520     * @param x
2521     * @param y
2522     */
2523    rMoveTo(x: number, y: number): Path;
2524
2525    /**
2526     * Relative version of quadTo.
2527     * @param x1
2528     * @param y1
2529     * @param x2
2530     * @param y2
2531     */
2532    rQuadTo(x1: number, y1: number, x2: number, y2: number): Path;
2533
2534    /**
2535     * Sets FillType, the rule used to fill Path.
2536     * @param fill
2537     */
2538    setFillType(fill: FillType): void;
2539
2540    /**
2541     * Specifies whether Path is volatile; whether it will be altered or discarded
2542     * by the caller after it is drawn. Path by default have volatile set false.
2543     *
2544     * Mark animating or temporary paths as volatile to improve performance.
2545     * Mark unchanging Path non-volatile to improve repeated rendering.
2546     * @param volatile
2547     */
2548    setIsVolatile(volatile: boolean): void;
2549
2550    /**
2551     * Set this path to a set of non-overlapping contours that describe the
2552     * same area as the original path.
2553     * The curve order is reduced where possible so that cubics may
2554     * be turned into quadratics, and quadratics maybe turned into lines.
2555     *
2556     * Returns true if operation was able to produce a result.
2557     */
2558    simplify(): boolean;
2559
2560    /**
2561     * Turns this path into the filled equivalent of the stroked path. Returns null if the operation
2562     * fails (e.g. the path is a hairline).
2563     * @param opts - describe how stroked path should look.
2564     */
2565    stroke(opts?: StrokeOpts): Path | null;
2566
2567    /**
2568     * Serializes the contents of this path as a series of commands.
2569     * The first item will be a verb, followed by any number of arguments needed. Then it will
2570     * be followed by another verb, more arguments and so on.
2571     */
2572    toCmds(): Float32Array;
2573
2574    /**
2575     * Returns this path as an SVG string.
2576     */
2577    toSVGString(): string;
2578
2579    /**
2580     * Takes a 3x3 matrix as either an array or as 9 individual params.
2581     * @param args
2582     */
2583    transform(...args: any[]): Path;
2584
2585    /**
2586     * Take start and stop "t" values (values between 0...1), and modify this path such that
2587     * it is a subset of the original path.
2588     * The trim values apply to the entire path, so if it contains several contours, all of them
2589     * are including in the calculation.
2590     * Null is returned if either input value is NaN.
2591     * @param startT - a value in the range [0.0, 1.0]. 0.0 is the beginning of the path.
2592     * @param stopT  - a value in the range [0.0, 1.0]. 1.0 is the end of the path.
2593     * @param isComplement
2594     */
2595    trim(startT: number, stopT: number, isComplement: boolean): Path | null;
2596}
2597
2598/**
2599 * See SkPathEffect.h for more on this class. The objects are opaque.
2600 */
2601export type PathEffect = EmbindObject<PathEffect>;
2602
2603/**
2604 * See SkPicture.h for more information on this class.
2605 *
2606 * Of note, SkPicture is *not* what is colloquially thought of as a "picture" (what we
2607 * call a bitmap). An SkPicture is a series of draw commands.
2608 */
2609export interface SkPicture extends EmbindObject<SkPicture> {
2610    /**
2611     *  Returns a new shader that will draw with this picture.
2612     *
2613     *  @param tmx  The tiling mode to use when sampling in the x-direction.
2614     *  @param tmy  The tiling mode to use when sampling in the y-direction.
2615     *  @param mode How to filter the tiles
2616     *  @param localMatrix Optional matrix used when sampling
2617     *  @param tileRect The tile rectangle in picture coordinates: this represents the subset
2618     *              (or superset) of the picture used when building a tile. It is not
2619     *              affected by localMatrix and does not imply scaling (only translation
2620     *              and cropping). If null, the tile rect is considered equal to the picture
2621     *              bounds.
2622     */
2623    makeShader(tmx: TileMode, tmy: TileMode, mode: FilterMode,
2624               localMatrix?: InputMatrix, tileRect?: InputRect): Shader;
2625
2626    /**
2627     * Returns the serialized format of this SkPicture. The format may change at anytime and
2628     * no promises are made for backwards or forward compatibility.
2629     */
2630    serialize(): Uint8Array | null;
2631}
2632
2633export interface PictureRecorder extends EmbindObject<PictureRecorder> {
2634    /**
2635     * Returns a canvas on which to draw. When done drawing, call finishRecordingAsPicture()
2636     *
2637     * @param bounds - a rect to cull the results.
2638     */
2639    beginRecording(bounds: InputRect): Canvas;
2640
2641    /**
2642     * Returns the captured draw commands as a picture and invalidates the canvas returned earlier.
2643     */
2644    finishRecordingAsPicture(): SkPicture;
2645}
2646
2647/**
2648 * See SkRuntimeEffect.h for more details.
2649 */
2650export interface RuntimeEffect extends EmbindObject<RuntimeEffect> {
2651    /**
2652     * Returns a shader executed using the given uniform data.
2653     * @param uniforms
2654     * @param localMatrix
2655     */
2656    makeShader(uniforms: Float32Array | number[] | MallocObj,
2657               localMatrix?: InputMatrix): Shader;
2658
2659    /**
2660     * Returns a shader executed using the given uniform data and the children as inputs.
2661     * @param uniforms
2662     * @param children
2663     * @param localMatrix
2664     */
2665    makeShaderWithChildren(uniforms: Float32Array | number[] | MallocObj,
2666                           children?: Shader[], localMatrix?: InputMatrix): Shader;
2667
2668    /**
2669     * Returns the nth uniform from the effect.
2670     * @param index
2671     */
2672    getUniform(index: number): SkSLUniform;
2673
2674    /**
2675     * Returns the number of uniforms on the effect.
2676     */
2677    getUniformCount(): number;
2678
2679    /**
2680     * Returns the total number of floats across all uniforms on the effect. This is the length
2681     * of the uniforms array expected by makeShader. For example, an effect with a single float3
2682     * uniform, would return 1 from `getUniformCount()`, but 3 from `getUniformFloatCount()`.
2683     */
2684    getUniformFloatCount(): number;
2685
2686    /**
2687     * Returns the name of the nth effect uniform.
2688     * @param index
2689     */
2690    getUniformName(index: number): string;
2691}
2692
2693/**
2694 * See SkShader.h for more on this class. The objects are opaque.
2695 */
2696export type Shader = EmbindObject<Shader>;
2697
2698export interface Surface extends EmbindObject<Surface> {
2699    /**
2700     * A convenient way to draw exactly once on the canvas associated with this surface.
2701     * This requires an environment where a global function called requestAnimationFrame is
2702     * available (e.g. on the web, not on Node). Users do not need to flush the surface,
2703     * or delete/dispose of it as that is taken care of automatically with this wrapper.
2704     *
2705     * Node users should call getCanvas() and work with that canvas directly.
2706     */
2707    drawOnce(drawFrame: (_: Canvas) => void): void;
2708
2709    /**
2710     * Clean up the surface and any extra memory.
2711     * [Deprecated]: In the future, calls to delete() will be sufficient to clean up the memory.
2712     */
2713    dispose(): void;
2714
2715    /**
2716     * Make sure any queued draws are sent to the screen or the GPU.
2717     */
2718    flush(): void;
2719
2720    /**
2721     * Return a canvas that is backed by this surface. Any draws to the canvas will (eventually)
2722     * show up on the surface. The returned canvas is owned by the surface and does NOT need to
2723     * be cleaned up by the client.
2724     */
2725    getCanvas(): Canvas;
2726
2727    /**
2728     * Returns the height of this surface in pixels.
2729     */
2730    height(): number;
2731
2732    /**
2733     * Returns the ImageInfo associated with this surface.
2734     */
2735    imageInfo(): ImageInfo;
2736
2737    /**
2738     * Creates an Image from the provided texture and info. The Image will own the texture;
2739     * when the image is deleted, the texture will be cleaned up.
2740     * @param tex
2741     * @param info - describes the content of the texture.
2742     */
2743    makeImageFromTexture(tex: WebGLTexture, info: ImageInfo): Image | null;
2744
2745    /**
2746     * Returns a texture-backed image based on the content in src. It uses RGBA_8888, unpremul
2747     * and SRGB - for more control, use makeImageFromTexture.
2748     *
2749     * The underlying texture for this image will be created immediately from src, so
2750     * it can be disposed of after this call. This image will *only* be usable for this
2751     * surface (because WebGL textures are not transferable to other WebGL contexts).
2752     * For an image that can be used across multiple surfaces, at the cost of being lazily
2753     * loaded, see MakeLazyImageFromTextureSource.
2754     *
2755     * Not available for software-backed surfaces.
2756     * @param src
2757     * @param info - If provided, will be used to determine the width/height/format of the
2758     *               source image. If not, sensible defaults will be used.
2759     * @param srcIsPremul - set to true if the src data has premultiplied alpha. Otherwise, it will
2760     *               be assumed to be Unpremultiplied. Note: if this is true and info specifies
2761     *               Unpremul, Skia will not convert the src pixels first.
2762     */
2763    makeImageFromTextureSource(src: TextureSource, info?: ImageInfo | PartialImageInfo,
2764                               srcIsPremul?: boolean): Image | null;
2765
2766    /**
2767     * Returns current contents of the surface as an Image. This image will be optimized to be
2768     * drawn to another surface of the same type. For example, if this surface is backed by the
2769     * GPU, the returned Image will be backed by a GPU texture.
2770     */
2771    makeImageSnapshot(bounds?: InputIRect): Image;
2772
2773    /**
2774     * Returns a compatible Surface, haring the same raster or GPU properties of the original.
2775     * The pixels are not shared.
2776     * @param info - width, height, etc of the Surface.
2777     */
2778    makeSurface(info: ImageInfo): Surface;
2779
2780    /**
2781     * Returns if this Surface is a GPU-backed surface or not.
2782     */
2783    reportBackendTypeIsGPU(): boolean;
2784
2785    /**
2786     * A convenient way to draw multiple frames on the canvas associated with this surface.
2787     * This requires an environment where a global function called requestAnimationFrame is
2788     * available (e.g. on the web, not on Node). Users do not need to flush the surface,
2789     * as that is taken care of automatically with this wrapper.
2790     *
2791     * Users should probably call surface.requestAnimationFrame in the callback function to
2792     * draw multiple frames, e.g. of an animation.
2793     *
2794     * Node users should call getCanvas() and work with that canvas directly.
2795     *
2796     * Returns the animation id.
2797     */
2798    requestAnimationFrame(drawFrame: (_: Canvas) => void): number;
2799
2800    /**
2801     * If this surface is GPU-backed, return the sample count of the surface.
2802     */
2803    sampleCnt(): number;
2804
2805    /**
2806     * Updates the underlying GPU texture of the image to be the contents of the provided
2807     * TextureSource. Has no effect on CPU backend or if img was not created with either
2808     * makeImageFromTextureSource or makeImageFromTexture.
2809     * If the provided TextureSource is of different dimensions than the Image, the contents
2810     * will be deformed (e.g. squished). The ColorType, AlphaType, and ColorSpace of src should
2811     * match the original settings used to create the Image or it may draw strange.
2812     *
2813     * @param img - A texture-backed Image.
2814     * @param src - A valid texture source of any dimensions.
2815     * @param srcIsPremul - set to true if the src data has premultiplied alpha. Otherwise, it will
2816     *               be assumed to be Unpremultiplied. Note: if this is true and the image was
2817     *               created with Unpremul, Skia will not convert.
2818     */
2819    updateTextureFromSource(img: Image, src: TextureSource, srcIsPremul?: boolean): void;
2820
2821    /**
2822     * Returns the width of this surface in pixels.
2823     */
2824    width(): number;
2825}
2826
2827/**
2828 * See SkTextBlob.h for more on this class. The objects are opaque.
2829 */
2830export type TextBlob = EmbindObject<TextBlob>;
2831
2832/**
2833 * See SkTypeface.h for more on this class. The objects are opaque.
2834 */
2835export interface Typeface extends EmbindObject<Typeface> {
2836    /**
2837     * Retrieves the glyph ids for each code point in the provided string. Note that glyph IDs
2838     * are typeface-dependent; different faces may have different ids for the same code point.
2839     * @param str
2840     * @param numCodePoints - the number of code points in the string. Defaults to str.length.
2841     * @param output - if provided, the results will be copied into this array.
2842     */
2843    getGlyphIDs(str: string, numCodePoints?: number,
2844                output?: GlyphIDArray): GlyphIDArray;
2845}
2846
2847/**
2848 * See SkVertices.h for more on this class.
2849 */
2850export interface Vertices extends EmbindObject<Vertices> {
2851    /**
2852     * Return the bounding area for the vertices.
2853     * @param outputArray - if provided, the bounding box will be copied into this array instead of
2854     *                      allocating a new one.
2855     */
2856    bounds(outputArray?: Rect): Rect;
2857
2858    /**
2859     * Return a unique ID for this vertices object.
2860     */
2861    uniqueID(): number;
2862}
2863
2864export interface SkottieAnimation extends EmbindObject<SkottieAnimation> {
2865    /**
2866     * Returns the animation duration in seconds.
2867     */
2868    duration(): number;
2869    /**
2870     * Returns the animation frame rate (frames / second).
2871     */
2872    fps(): number;
2873
2874    /**
2875     * Draws current animation frame. Must call seek or seekFrame first.
2876     * @param canvas
2877     * @param dstRect
2878     */
2879    render(canvas: Canvas, dstRect?: InputRect): void;
2880
2881    /**
2882     * [deprecated] - use seekFrame
2883     * @param t - value from [0.0, 1.0]; 0 is first frame, 1 is final frame.
2884     * @param damageRect - will copy damage frame into this if provided.
2885     */
2886    seek(t: number, damageRect?: Rect): Rect;
2887
2888    /**
2889     * Update the animation state to match |t|, specified as a frame index
2890     * i.e. relative to duration() * fps().
2891     *
2892     * Returns the rectangle that was affected by this animation.
2893     *
2894     * @param frame - Fractional values are allowed and meaningful - e.g.
2895     *                0.0 -> first frame
2896     *                1.0 -> second frame
2897     *                0.5 -> halfway between first and second frame
2898     * @param damageRect - will copy damage frame into this if provided.
2899     */
2900    seekFrame(frame: number, damageRect?: Rect): Rect;
2901
2902    /**
2903     * Return the size of this animation.
2904     * @param outputSize - If provided, the size will be copied into here as width, height.
2905     */
2906    size(outputSize?: Point): Point;
2907    version(): string;
2908}
2909
2910/**
2911 * Options used for Path.stroke(). If an option is omitted, a sensible default will be used.
2912 */
2913export interface StrokeOpts {
2914    /** The width of the stroked lines. */
2915    width?: number;
2916    miter_limit?: number;
2917    /**
2918     * if > 1, increase precision, else if (0 < resScale < 1) reduce precision to
2919     * favor speed and size
2920     */
2921    precision?: number;
2922    join?: StrokeJoin;
2923    cap?: StrokeCap;
2924}
2925
2926export interface StrutStyle {
2927    strutEnabled?: boolean;
2928    fontFamilies?: string[];
2929    fontStyle?: FontStyle;
2930    fontSize?: number;
2931    heightMultiplier?: number;
2932    halfLeading?: boolean;
2933    leading?: number;
2934    forceStrutHeight?: boolean;
2935}
2936
2937export interface TextFontFeatures {
2938    name: string;
2939    value: number;
2940}
2941
2942export interface TextFontVariations {
2943    axis: string;
2944    value: number;
2945}
2946
2947export interface TextShadow {
2948    color?: InputColor;
2949    /**
2950     * 2d array for x and y offset. Defaults to [0, 0]
2951     */
2952    offset?: number[];
2953    blurRadius?: number;
2954}
2955
2956export interface TextStyle {
2957    backgroundColor?: InputColor;
2958    color?: InputColor;
2959    decoration?: number;
2960    decorationColor?: InputColor;
2961    decorationThickness?: number;
2962    decorationStyle?: DecorationStyle;
2963    fontFamilies?: string[];
2964    fontFeatures?: TextFontFeatures[];
2965    fontSize?: number;
2966    fontStyle?: FontStyle;
2967    fontVariations?: TextFontVariations[];
2968    foregroundColor?: InputColor;
2969    heightMultiplier?: number;
2970    halfLeading?: boolean;
2971    letterSpacing?: number;
2972    locale?: string;
2973    shadows?: TextShadow[];
2974    textBaseline?: TextBaseline;
2975    wordSpacing?: number;
2976}
2977
2978export interface TonalColorsInput {
2979    ambient: InputColor;
2980    spot: InputColor;
2981}
2982
2983export interface TonalColorsOutput {
2984    ambient: Color;
2985    spot: Color;
2986}
2987
2988export interface TypefaceFontProvider extends EmbindObject<TypefaceFontProvider> {
2989    /**
2990     * Registers a given typeface with the given family name (ignoring whatever name the
2991     * typface has for itself).
2992     * @param bytes - the raw bytes for a typeface.
2993     * @param family
2994     */
2995    registerFont(bytes: ArrayBuffer | Uint8Array, family: string): void;
2996}
2997
2998export interface URange {
2999    start: number;
3000    end: number;
3001}
3002
3003/**
3004 * Options for configuring a WebGL context. If an option is omitted, a sensible default will
3005 * be used. These are defined by the WebGL standards.
3006 */
3007export interface WebGLOptions {
3008    alpha?: number;
3009    antialias?: number;
3010    depth?: number;
3011    enableExtensionsByDefault?: number;
3012    explicitSwapControl?: number;
3013    failIfMajorPerformanceCaveat?: number;
3014    majorVersion?: number;
3015    minorVersion?: number;
3016    preferLowPowerToHighPerformance?: number;
3017    premultipliedAlpha?: number;
3018    preserveDrawingBuffer?: number;
3019    renderViaOffscreenBackBuffer?: number;
3020    stencil?: number;
3021}
3022
3023/**
3024 * Options for configuring a canvas WebGPU context. If an option is omitted, a default specified by
3025 * the WebGPU standard will be used.
3026 */
3027export interface WebGPUCanvasOptions {
3028    format?: GPUTextureFormat;
3029    alphaMode?: GPUCanvasAlphaMode;
3030}
3031
3032export interface DefaultConstructor<T> {
3033    new (): T;
3034}
3035
3036export interface ColorMatrixHelpers {
3037    /**
3038     * Returns a new ColorMatrix that is the result of multiplying outer*inner
3039     * @param outer
3040     * @param inner
3041     */
3042    concat(outer: ColorMatrix, inner: ColorMatrix): ColorMatrix;
3043
3044    /**
3045     * Returns an identity ColorMatrix.
3046     */
3047    identity(): ColorMatrix;
3048
3049    /**
3050     * Sets the 4 "special" params that will translate the colors after they are multiplied
3051     * by the 4x4 matrix.
3052     * @param m
3053     * @param dr - delta red
3054     * @param dg - delta green
3055     * @param db - delta blue
3056     * @param da - delta alpha
3057     */
3058    postTranslate(m: ColorMatrix, dr: number, dg: number, db: number, da: number): ColorMatrix;
3059
3060    /**
3061     * Returns a new ColorMatrix that is rotated around a given axis.
3062     * @param axis - 0 for red, 1 for green, 2 for blue
3063     * @param sine - sin(angle)
3064     * @param cosine - cos(angle)
3065     */
3066    rotated(axis: number, sine: number, cosine: number): ColorMatrix;
3067
3068    /**
3069     * Returns a new ColorMatrix that scales the colors as specified.
3070     * @param redScale
3071     * @param greenScale
3072     * @param blueScale
3073     * @param alphaScale
3074     */
3075    scaled(redScale: number, greenScale: number, blueScale: number,
3076           alphaScale: number): ColorMatrix;
3077}
3078
3079/**
3080 * A constructor for making an ImageData that is compatible with the Canvas2D emulation code.
3081 */
3082export interface ImageDataConstructor {
3083    new (width: number, height: number): EmulatedImageData;
3084    new (pixels: Uint8ClampedArray, width: number, height: number): EmulatedImageData;
3085}
3086
3087/**
3088 * TODO(kjlubick) Make this API return Float32Arrays
3089 */
3090export interface Matrix3x3Helpers {
3091    /**
3092     * Returns a new identity 3x3 matrix.
3093     */
3094    identity(): number[];
3095
3096    /**
3097     * Returns the inverse of the given 3x3 matrix or null if it is not invertible.
3098     * @param m
3099     */
3100    invert(m: Matrix3x3 | number[]): number[] | null;
3101
3102    /**
3103     * Maps the given 2d points according to the given 3x3 matrix.
3104     * @param m
3105     * @param points - the flattened points to map; the results are computed in place on this array.
3106     */
3107    mapPoints(m: Matrix3x3 | number[], points: number[]): number[];
3108
3109    /**
3110     * Multiplies the provided 3x3 matrices together from left to right.
3111     * @param matrices
3112     */
3113    multiply(...matrices: Array<(Matrix3x3 | number[])>): number[];
3114
3115    /**
3116     * Returns a new 3x3 matrix representing a rotation by n radians.
3117     * @param radians
3118     * @param px - the X value to rotate around, defaults to 0.
3119     * @param py - the Y value to rotate around, defaults to 0.
3120     */
3121    rotated(radians: AngleInRadians, px?: number, py?: number): number[];
3122
3123    /**
3124     * Returns a new 3x3 matrix representing a scale in the x and y directions.
3125     * @param sx - the scale in the X direction.
3126     * @param sy - the scale in the Y direction.
3127     * @param px - the X value to scale from, defaults to 0.
3128     * @param py - the Y value to scale from, defaults to 0.
3129     */
3130    scaled(sx: number, sy: number, px?: number, py?: number): number[];
3131
3132    /**
3133     * Returns a new 3x3 matrix representing a scale in the x and y directions.
3134     * @param kx - the kurtosis in the X direction.
3135     * @param ky - the kurtosis in the Y direction.
3136     * @param px - the X value to skew from, defaults to 0.
3137     * @param py - the Y value to skew from, defaults to 0.
3138     */
3139    skewed(kx: number, ky: number, px?: number, py?: number): number[];
3140
3141    /**
3142     * Returns a new 3x3 matrix representing a translation in the x and y directions.
3143     * @param dx
3144     * @param dy
3145     */
3146    translated(dx: number, dy: number): number[];
3147}
3148
3149/**
3150 * See SkM44.h for more details.
3151 */
3152export interface Matrix4x4Helpers {
3153    /**
3154     * Returns a new identity 4x4 matrix.
3155     */
3156    identity(): number[];
3157
3158    /**
3159     * Returns the inverse of the given 4x4 matrix or null if it is not invertible.
3160     * @param matrix
3161     */
3162    invert(matrix: Matrix4x4 | number[]): number[] | null;
3163
3164    /**
3165     * Return a new 4x4 matrix representing a camera at eyeVec, pointed at centerVec.
3166     * @param eyeVec
3167     * @param centerVec
3168     * @param upVec
3169     */
3170    lookat(eyeVec: Vector3, centerVec: Vector3, upVec: Vector3): number[];
3171
3172    /**
3173     * Multiplies the provided 4x4 matrices together from left to right.
3174     * @param matrices
3175     */
3176    multiply(...matrices: Array<(Matrix4x4 | number[])>): number[];
3177
3178    /**
3179     * Returns the inverse of the given 4x4 matrix or throws if it is not invertible.
3180     * @param matrix
3181     */
3182    mustInvert(matrix: Matrix4x4 | number[]): number[];
3183
3184    /**
3185     * Returns a new 4x4 matrix representing a perspective.
3186     * @param near
3187     * @param far
3188     * @param radians
3189     */
3190    perspective(near: number, far: number, radians: AngleInRadians): number[];
3191
3192    /**
3193     * Returns the value at the specified row and column of the given 4x4 matrix.
3194     * @param matrix
3195     * @param row
3196     * @param col
3197     */
3198    rc(matrix: Matrix4x4 | number[], row: number, col: number): number;
3199
3200    /**
3201     * Returns a new 4x4 matrix representing a rotation around the provided vector.
3202     * @param axis
3203     * @param radians
3204     */
3205    rotated(axis: Vector3, radians: AngleInRadians): number[];
3206
3207    /**
3208     * Returns a new 4x4 matrix representing a rotation around the provided vector.
3209     * Rotation is provided redundantly as both sin and cos values.
3210     * This rotate can be used when you already have the cosAngle and sinAngle values
3211     * so you don't have to atan(cos/sin) to call roatated() which expects an angle in radians.
3212     * This does no checking! Behavior for invalid sin or cos values or non-normalized axis vectors
3213     * is incorrect. Prefer rotated().
3214     * @param axis
3215     * @param sinAngle
3216     * @param cosAngle
3217     */
3218    rotatedUnitSinCos(axis: Vector3, sinAngle: number, cosAngle: number): number[];
3219
3220    /**
3221     * Returns a new 4x4 matrix representing a scale by the provided vector.
3222     * @param vec
3223     */
3224    scaled(vec: Vector3): number[];
3225
3226    /**
3227     * Returns a new 4x4 matrix that sets up a 3D perspective view from a given camera.
3228     * @param area - describes the viewport. (0, 0, canvas_width, canvas_height) suggested.
3229     * @param zScale - describes the scale of the z axis. min(width, height)/2 suggested
3230     * @param cam
3231     */
3232    setupCamera(area: InputRect, zScale: number, cam: Camera): number[];
3233
3234    /**
3235     * Returns a new 4x4 matrix representing a translation by the provided vector.
3236     * @param vec
3237     */
3238    translated(vec: Vector3): number[];
3239
3240    /**
3241     * Returns a new 4x4 matrix that is the transpose of this 4x4 matrix.
3242     * @param matrix
3243     */
3244    transpose(matrix: Matrix4x4 | number[]): number[];
3245}
3246
3247export interface ParagraphBuilderFactory {
3248    /**
3249     * Creates a ParagraphBuilder using the fonts available from the given font manager.
3250     * @param style
3251     * @param fontManager
3252     */
3253    Make(style: ParagraphStyle, fontManager: FontMgr): ParagraphBuilder;
3254
3255    /**
3256     * Creates a ParagraphBuilder using the fonts available from the given font provider.
3257     * @param style
3258     * @param fontSrc
3259     */
3260    MakeFromFontProvider(style: ParagraphStyle, fontSrc: TypefaceFontProvider): ParagraphBuilder;
3261
3262    /**
3263     * Return a shaped array of lines
3264     */
3265    ShapeText(text: string, runs: FontBlock[], width?: number): ShapedLine[];
3266}
3267
3268export interface ParagraphStyleConstructor {
3269    /**
3270     * Fills out all optional fields with defaults. The emscripten bindings complain if there
3271     * is a field undefined and it was expecting a float (for example).
3272     * @param ps
3273     */
3274    new(ps: ParagraphStyle): ParagraphStyle;
3275}
3276
3277/**
3278 * See SkColorFilter.h for more.
3279 */
3280export interface ColorFilterFactory {
3281    /**
3282     * Makes a color filter with the given color, blend mode, and colorSpace.
3283     * @param color
3284     * @param mode
3285     * @param colorSpace - If omitted, will use SRGB
3286     */
3287    MakeBlend(color: InputColor, mode: BlendMode, colorSpace?: ColorSpace): ColorFilter;
3288
3289    /**
3290     * Makes a color filter composing two color filters.
3291     * @param outer
3292     * @param inner
3293     */
3294    MakeCompose(outer: ColorFilter, inner: ColorFilter): ColorFilter;
3295
3296    /**
3297     * Makes a color filter that is linearly interpolated between two other color filters.
3298     * @param t - a float in the range of 0.0 to 1.0.
3299     * @param dst
3300     * @param src
3301     */
3302    MakeLerp(t: number, dst: ColorFilter, src: ColorFilter): ColorFilter;
3303
3304    /**
3305     * Makes a color filter that converts between linear colors and sRGB colors.
3306     */
3307    MakeLinearToSRGBGamma(): ColorFilter;
3308
3309    /**
3310     * Creates a color filter using the provided color matrix.
3311     * @param cMatrix
3312     */
3313    MakeMatrix(cMatrix: InputColorMatrix): ColorFilter;
3314
3315    /**
3316     * Makes a color filter that converts between sRGB colors and linear colors.
3317     */
3318    MakeSRGBToLinearGamma(): ColorFilter;
3319
3320    /**
3321     * Makes a color filter that multiplies the luma of its input into the alpha channel,
3322     * and sets the red, green, and blue channels to zero.
3323     */
3324    MakeLuma(): ColorFilter;
3325}
3326
3327export interface ContourMeasureIterConstructor {
3328    /**
3329     * Creates an ContourMeasureIter with the given path.
3330     * @param path
3331     * @param forceClosed - if path should be forced close before measuring it.
3332     * @param resScale - controls the precision of the measure. values > 1 increase the
3333     *                   precision (and possibly slow down the computation).
3334     */
3335    new (path: Path, forceClosed: boolean, resScale: number): ContourMeasureIter;
3336}
3337
3338/**
3339 * See SkFont.h for more.
3340 */
3341export interface FontConstructor extends DefaultConstructor<Font> {
3342    /**
3343     * Constructs Font with default values with Typeface.
3344     * @param face
3345     * @param size - font size in points. If not specified, uses a default value.
3346     */
3347    new (face: Typeface | null, size?: number): Font;
3348
3349    /**
3350     * Constructs Font with default values with Typeface and size in points,
3351     * horizontal scale, and horizontal skew. Horizontal scale emulates condensed
3352     * and expanded fonts. Horizontal skew emulates oblique fonts.
3353     * @param face
3354     * @param size
3355     * @param scaleX
3356     * @param skewX
3357     */
3358    new (face: Typeface | null, size: number, scaleX: number, skewX: number): Font;
3359}
3360
3361export interface FontMgrFactory {
3362    /**
3363     * Create an FontMgr with the created font data. Returns null if buffers was empty.
3364     * @param buffers
3365     */
3366    FromData(...buffers: ArrayBuffer[]): FontMgr | null;
3367}
3368
3369/**
3370 * See //include/effects/SkImageFilters.h for more.
3371 */
3372export interface ImageFilterFactory {
3373    /**
3374     * Create a filter that takes a BlendMode and uses it to composite the two filters together.
3375     *
3376     *  At least one of background and foreground should be non-null in nearly all circumstances.
3377     *
3378     *  @param blend       The blend mode that defines the compositing operation
3379     *  @param background The Dst pixels used in blending; if null, use the dynamic source image
3380     *                    (e.g. a saved layer).
3381     *  @param foreground The Src pixels used in blending; if null, use the dynamic source image.
3382     */
3383    MakeBlend(blend: BlendMode, background: ImageFilter | null,
3384              foreground: ImageFilter | null): ImageFilter;
3385
3386    /**
3387     * Create a filter that blurs its input by the separate X and Y sigmas. The provided tile mode
3388     * is used when the blur kernel goes outside the input image.
3389     *
3390     * @param sigmaX - The Gaussian sigma value for blurring along the X axis.
3391     * @param sigmaY - The Gaussian sigma value for blurring along the Y axis.
3392     * @param mode
3393     * @param input - if null, it will use the dynamic source image (e.g. a saved layer)
3394     */
3395    MakeBlur(sigmaX: number, sigmaY: number, mode: TileMode,
3396             input: ImageFilter | null): ImageFilter;
3397
3398    /**
3399     * Create a filter that applies the color filter to the input filter results.
3400     * @param cf
3401     * @param input - if null, it will use the dynamic source image (e.g. a saved layer)
3402     */
3403    MakeColorFilter(cf: ColorFilter, input: ImageFilter | null): ImageFilter;
3404
3405    /**
3406     * Create a filter that composes 'inner' with 'outer', such that the results of 'inner' are
3407     * treated as the source bitmap passed to 'outer'.
3408     * If either param is null, the other param will be returned.
3409     * @param outer
3410     * @param inner - if null, it will use the dynamic source image (e.g. a saved layer)
3411     */
3412    MakeCompose(outer: ImageFilter | null, inner: ImageFilter | null): ImageFilter;
3413
3414    /**
3415     *  Create a filter that dilates each input pixel's channel values to the max value within the
3416     *  given radii along the x and y axes.
3417     *  @param radiusX  The distance to dilate along the x axis to either side of each pixel.
3418     *  @param radiusY  The distance to dilate along the y axis to either side of each pixel.
3419     *  @param input     if null, it will use the dynamic source image (e.g. a saved layer).
3420     */
3421    MakeDilate(radiusX: number, radiusY: number, input: ImageFilter | null): ImageFilter;
3422
3423    /**
3424     *  Create a filter that moves each pixel in its color input based on an (x,y) vector encoded
3425     *  in its displacement input filter. Two color components of the displacement image are
3426     *  mapped into a vector as scale * (color[xChannel], color[yChannel]), where the channel
3427     *  selectors are one of R, G, B, or A.
3428     *  The mapping takes the 0-255 RGBA values of the image and scales them to be [-0.5 to 0.5],
3429     *  in a similar fashion to https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDisplacementMap
3430     *
3431     *  At least one of displacement and color should be non-null in nearly all circumstances.
3432     *
3433     *  @param xChannel RGBA channel that encodes the x displacement per pixel.
3434     *  @param yChannel RGBA channel that encodes the y displacement per pixel.
3435     *  @param scale    Scale applied to displacement extracted from image.
3436     *  @param displacement The filter defining the displacement image, or null to use source.
3437     *  @param color   The filter providing the color pixels to be displaced, or null to use source.
3438     */
3439    MakeDisplacementMap(xChannel: ColorChannel, yChannel: ColorChannel, scale: number,
3440                        displacement: ImageFilter | null, color: ImageFilter | null): ImageFilter;
3441    /**
3442     *  Create a filter that draws a drop shadow under the input content. This filter produces an
3443     *  image that includes the inputs' content.
3444     *  @param dx       The X offset of the shadow.
3445     *  @param dy       The Y offset of the shadow.
3446     *  @param sigmaX   The blur radius for the shadow, along the X axis.
3447     *  @param sigmaY   The blur radius for the shadow, along the Y axis.
3448     *  @param color    The color of the drop shadow.
3449     *  @param input    The input filter; if null, it will use the dynamic source image.
3450     */
3451    MakeDropShadow(dx: number, dy: number, sigmaX: number, sigmaY: number, color: Color,
3452                   input: ImageFilter | null): ImageFilter;
3453
3454    /**
3455     *  Just like MakeDropShadow, except the input content is not in the resulting image.
3456     *  @param dx       The X offset of the shadow.
3457     *  @param dy       The Y offset of the shadow.
3458     *  @param sigmaX   The blur radius for the shadow, along the X axis.
3459     *  @param sigmaY   The blur radius for the shadow, along the Y axis.
3460     *  @param color    The color of the drop shadow.
3461     *  @param input    The input filter; if null, it will use the dynamic source image.
3462     */
3463    MakeDropShadowOnly(dx: number, dy: number, sigmaX: number, sigmaY: number, color: Color,
3464                       input: ImageFilter | null): ImageFilter;
3465
3466    /**
3467     *  Create a filter that erodes each input pixel's channel values to the minimum channel value
3468     *  within the given radii along the x and y axes.
3469     *  @param radiusX  The distance to erode along the x axis to either side of each pixel.
3470     *  @param radiusY  The distance to erode along the y axis to either side of each pixel.
3471     *  @param input     if null, it will use the dynamic source image (e.g. a saved layer).
3472     */
3473    MakeErode(radiusX: number, radiusY: number, input: ImageFilter | null): ImageFilter;
3474
3475    /**
3476     *  Create a filter using the given image as a source. Returns null if 'image' is null.
3477     *
3478     *  @param img      The image that is output by the filter, subset by 'srcRect'.
3479     *  @param sampling The sampling to use when drawing the image.
3480     */
3481    MakeImage(img: Image, sampling: FilterOptions | CubicResampler): ImageFilter | null;
3482
3483    /**
3484     *  Create a filter that draws the 'srcRect' portion of image into 'dstRect' using the given
3485     *  filter quality. Similar to Canvas.drawImageRect. Returns null if 'image' is null.
3486     *
3487     *  @param img      The image that is output by the filter, subset by 'srcRect'.
3488     *  @param sampling The sampling to use when drawing the image.
3489     *  @param srcRect  The source pixels sampled into 'dstRect'.
3490     *  @param dstRect  The local rectangle to draw the image into.
3491     */
3492    MakeImage(img: Image, sampling: FilterOptions | CubicResampler,
3493              srcRect: InputRect, dstRect: InputRect): ImageFilter | null;
3494
3495    /**
3496     * Create a filter that transforms the input image by 'matrix'. This matrix transforms the
3497     * local space, which means it effectively happens prior to any transformation coming from the
3498     * Canvas initiating the filtering.
3499     * @param matr
3500     * @param sampling
3501     * @param input - if null, it will use the dynamic source image (e.g. a saved layer)
3502     */
3503    MakeMatrixTransform(matr: InputMatrix, sampling: FilterOptions | CubicResampler,
3504                        input: ImageFilter | null): ImageFilter;
3505
3506    /**
3507     *  Create a filter that offsets the input filter by the given vector.
3508     *  @param dx       The x offset in local space that the image is shifted.
3509     *  @param dy       The y offset in local space that the image is shifted.
3510     *  @param input    The input that will be moved, if null, will use the dynamic source image.
3511     */
3512    MakeOffset(dx: number, dy: number, input: ImageFilter | null): ImageFilter;
3513
3514    /**
3515     * Transforms a shader into an image filter
3516     *
3517     * @param shader - The Shader to be transformed
3518     */
3519   MakeShader(shader: Shader): ImageFilter;
3520}
3521
3522/**
3523 * See SkMaskFilter.h for more details.
3524 */
3525export interface MaskFilterFactory {
3526    /**
3527     * Create a blur maskfilter
3528     * @param style
3529     * @param sigma - Standard deviation of the Gaussian blur to apply. Must be > 0.
3530     * @param respectCTM - if true the blur's sigma is modified by the CTM.
3531     */
3532    MakeBlur(style: BlurStyle, sigma: number, respectCTM: boolean): MaskFilter;
3533}
3534
3535/**
3536 * Contains the ways to create a Path.
3537 */
3538export interface PathConstructorAndFactory extends DefaultConstructor<Path> {
3539    /**
3540     * Returns true if the two paths contain equal verbs and equal weights.
3541     * @param path1 first path to compate
3542     * @param path2 second path to compare
3543     * @return      true if Path can be interpolated equivalent
3544     */
3545     CanInterpolate(path1: Path, path2: Path): boolean;
3546
3547    /**
3548     * Creates a new path from the given list of path commands. If this fails, null will be
3549     * returned instead.
3550     * @param cmds
3551     */
3552    MakeFromCmds(cmds: InputCommands): Path | null;
3553
3554    /**
3555     * Creates a new path by combining the given paths according to op. If this fails, null will
3556     * be returned instead.
3557     * @param one
3558     * @param two
3559     * @param op
3560     */
3561    MakeFromOp(one: Path, two: Path, op: PathOp): Path | null;
3562
3563    /**
3564     * Interpolates between Path with point array of equal size.
3565     * Copy verb array and weights to result, and set result path to a weighted
3566     * average of this path array and ending path.
3567     *
3568     *  weight is most useful when between zero (ending path) and
3569     *  one (this path); will work with values outside of this
3570     *  range.
3571     *
3572     * interpolate() returns undefined if path is not
3573     * the same size as ending path. Call isInterpolatable() to check Path
3574     * compatibility prior to calling interpolate().
3575     *
3576     * @param start path to interpolate from
3577     * @param end  path to interpolate with
3578     * @param weight  contribution of this path, and
3579     *                 one minus contribution of ending path
3580     * @return        Path replaced by interpolated averages or null if
3581     *                not interpolatable
3582     */
3583    MakeFromPathInterpolation(start: Path, end: Path, weight: number): Path | null;
3584
3585    /**
3586     * Creates a new path from the provided SVG string. If this fails, null will be
3587     * returned instead.
3588     * @param str
3589     */
3590    MakeFromSVGString(str: string): Path | null;
3591
3592    /**
3593     * Creates a new path using the provided verbs and associated points and weights. The process
3594     * reads the first verb from verbs and then the appropriate number of points from the
3595     * FlattenedPointArray (e.g. 2 points for moveTo, 4 points for quadTo, etc). If the verb is
3596     * a conic, a weight will be read from the WeightList.
3597     * If the data is malformed (e.g. not enough points), the resulting path will be incomplete.
3598     * @param verbs - the verbs that create this path, in the order of being drawn.
3599     * @param points - represents n points with 2n floats.
3600     * @param weights - used if any of the verbs are conics, can be omitted otherwise.
3601     */
3602    MakeFromVerbsPointsWeights(verbs: VerbList, points: InputFlattenedPointArray,
3603                               weights?: WeightList): Path;
3604}
3605
3606/**
3607 * See SkPathEffect.h for more details.
3608 */
3609export interface PathEffectFactory {
3610    /**
3611     * Returns a PathEffect that can turn sharp corners into rounded corners.
3612     * @param radius - if <=0, returns null
3613     */
3614    MakeCorner(radius: number): PathEffect | null;
3615
3616    /**
3617     * Returns a PathEffect that add dashes to the path.
3618     *
3619     * See SkDashPathEffect.h for more details.
3620     *
3621     * @param intervals - even number of entries with even indicies specifying the length of
3622     *                    the "on" intervals, and the odd indices specifying the length of "off".
3623     * @param phase - offset length into the intervals array. Defaults to 0.
3624     */
3625    MakeDash(intervals: number[], phase?: number): PathEffect;
3626
3627    /**
3628     * Returns a PathEffect that breaks path into segments of segLength length, and randomly move
3629     * the endpoints away from the original path by a maximum of deviation.
3630     * @param segLength - length of the subsegments.
3631     * @param dev - limit of the movement of the endpoints.
3632     * @param seedAssist - modifies the randomness. See SkDiscretePathEffect.h for more.
3633     */
3634    MakeDiscrete(segLength: number, dev: number, seedAssist: number): PathEffect;
3635
3636    /**
3637     * Returns a PathEffect that will fill the drawing path with a pattern made by applying
3638     * the given matrix to a repeating set of infinitely long lines of the given width.
3639     * For example, the scale of the provided matrix will determine how far apart the lines
3640     * should be drawn its rotation affects the lines' orientation.
3641     * @param width - must be >= 0
3642     * @param matrix
3643     */
3644    MakeLine2D(width: number, matrix: InputMatrix): PathEffect | null;
3645
3646    /**
3647     * Returns a PathEffect which implements dashing by replicating the specified path.
3648     *   @param path The path to replicate (dash)
3649     *   @param advance The space between instances of path
3650     *   @param phase distance (mod advance) along path for its initial position
3651     *   @param style how to transform path at each point (based on the current
3652     *                position and tangent)
3653     */
3654    MakePath1D(path: Path, advance: number, phase: number, style: Path1DEffectStyle):
3655        PathEffect | null;
3656
3657    /**
3658     * Returns a PathEffect that will fill the drawing path with a pattern by repeating the
3659     * given path according to the provided matrix. For example, the scale of the matrix
3660     * determines how far apart the path instances should be drawn.
3661     * @param matrix
3662     * @param path
3663     */
3664    MakePath2D(matrix: InputMatrix, path: Path): PathEffect | null;
3665}
3666
3667/**
3668 * See RuntimeEffect.h for more details.
3669 */
3670export interface DebugTrace extends EmbindObject<DebugTrace> {
3671    writeTrace(): string;
3672}
3673
3674export interface TracedShader {
3675    shader: Shader;
3676    debugTrace: DebugTrace;
3677}
3678
3679export interface RuntimeEffectFactory {
3680    /**
3681     * Compiles a RuntimeEffect from the given shader code.
3682     * @param sksl - Source code for a shader written in SkSL
3683     * @param callback - will be called with any compilation error. If not provided, errors will
3684     *                   be printed to console.log().
3685     */
3686    Make(sksl: string, callback?: (err: string) => void): RuntimeEffect | null;
3687
3688    /**
3689     * Adds debug tracing to an existing RuntimeEffect.
3690     * @param shader - An already-assembled shader, created with RuntimeEffect.makeShader.
3691     * @param traceCoordX - the X coordinate of the device-space pixel to trace
3692     * @param traceCoordY - the Y coordinate of the device-space pixel to trace
3693     */
3694    MakeTraced(shader: Shader, traceCoordX: number, traceCoordY: number): TracedShader;
3695}
3696
3697/**
3698 * For more information, see SkShaders.h.
3699 */
3700export interface ShaderFactory {
3701    /**
3702     * Returns a shader that combines the given shaders with a BlendMode.
3703     * @param mode
3704     * @param one
3705     * @param two
3706     */
3707    MakeBlend(mode: BlendMode, one: Shader, two: Shader): Shader;
3708
3709    /**
3710     * Returns a shader with a given color and colorspace.
3711     * @param color
3712     * @param space
3713     */
3714    MakeColor(color: InputColor, space: ColorSpace): Shader;
3715
3716    /**
3717     * Returns a shader with Perlin Fractal Noise.
3718     * See SkPerlinNoiseShader.h for more details
3719     * @param baseFreqX - base frequency in the X direction; range [0.0, 1.0]
3720     * @param baseFreqY - base frequency in the Y direction; range [0.0, 1.0]
3721     * @param octaves
3722     * @param seed
3723     * @param tileW - if this and tileH are non-zero, the frequencies will be modified so that the
3724     *                noise will be tileable for the given size.
3725     * @param tileH - if this and tileW are non-zero, the frequencies will be modified so that the
3726     *                noise will be tileable for the given size.
3727     */
3728    MakeFractalNoise(baseFreqX: number, baseFreqY: number, octaves: number, seed: number,
3729                     tileW: number, tileH: number): Shader;
3730
3731    /**
3732     * Returns a shader that generates a linear gradient between the two specified points.
3733     * See SkGradientShader.h for more.
3734     * @param start
3735     * @param end
3736     * @param colors - colors to be distributed between start and end.
3737     * @param pos - May be null. The relative positions of colors. If supplied must be same length
3738     *              as colors.
3739     * @param mode
3740     * @param localMatrix
3741     * @param flags - By default gradients will interpolate their colors in unpremul space
3742     *                and then premultiply each of the results. By setting this to 1, the
3743     *                gradients will premultiply their colors first, and then interpolate
3744     *                between them.
3745     * @param colorSpace
3746     */
3747    MakeLinearGradient(start: InputPoint, end: InputPoint, colors: InputFlexibleColorArray,
3748                       pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix,
3749                       flags?: number, colorSpace?: ColorSpace): Shader;
3750
3751    /**
3752     * Returns a shader that generates a radial gradient given the center and radius.
3753     * See SkGradientShader.h for more.
3754     * @param center
3755     * @param radius
3756     * @param colors - colors to be distributed between the center and edge.
3757     * @param pos - May be null. The relative positions of colors. If supplied must be same length
3758     *              as colors. Range [0.0, 1.0]
3759     * @param mode
3760     * @param localMatrix
3761     * @param flags - 0 to interpolate colors in unpremul, 1 to interpolate colors in premul.
3762     * @param colorSpace
3763     */
3764    MakeRadialGradient(center: InputPoint, radius: number, colors: InputFlexibleColorArray,
3765                       pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix,
3766                       flags?: number, colorSpace?: ColorSpace): Shader;
3767
3768    /**
3769     * Returns a shader that generates a sweep gradient given a center.
3770     * See SkGradientShader.h for more.
3771     * @param cx
3772     * @param cy
3773     * @param colors - colors to be distributed around the center, within the provided angles.
3774     * @param pos - May be null. The relative positions of colors. If supplied must be same length
3775     *              as colors. Range [0.0, 1.0]
3776     * @param mode
3777     * @param localMatrix
3778     * @param flags - 0 to interpolate colors in unpremul, 1 to interpolate colors in premul.
3779     * @param startAngle - angle corresponding to 0.0. Defaults to 0 degrees.
3780     * @param endAngle - angle corresponding to 1.0. Defaults to 360 degrees.
3781     * @param colorSpace
3782     */
3783    MakeSweepGradient(cx: number, cy: number, colors: InputFlexibleColorArray,
3784                      pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix | null,
3785                      flags?: number, startAngle?: AngleInDegrees, endAngle?: AngleInDegrees,
3786                      colorSpace?: ColorSpace): Shader;
3787
3788    /**
3789     * Returns a shader with Perlin Turbulence.
3790     * See SkPerlinNoiseShader.h for more details
3791     * @param baseFreqX - base frequency in the X direction; range [0.0, 1.0]
3792     * @param baseFreqY - base frequency in the Y direction; range [0.0, 1.0]
3793     * @param octaves
3794     * @param seed
3795     * @param tileW - if this and tileH are non-zero, the frequencies will be modified so that the
3796     *                noise will be tileable for the given size.
3797     * @param tileH - if this and tileW are non-zero, the frequencies will be modified so that the
3798     *                noise will be tileable for the given size.
3799     */
3800    MakeTurbulence(baseFreqX: number, baseFreqY: number, octaves: number, seed: number,
3801                   tileW: number, tileH: number): Shader;
3802
3803    /**
3804     * Returns a shader that generates a conical gradient given two circles.
3805     * See SkGradientShader.h for more.
3806     * @param start
3807     * @param startRadius
3808     * @param end
3809     * @param endRadius
3810     * @param colors
3811     * @param pos
3812     * @param mode
3813     * @param localMatrix
3814     * @param flags
3815     * @param colorSpace
3816     */
3817    MakeTwoPointConicalGradient(start: InputPoint, startRadius: number, end: InputPoint,
3818                                endRadius: number, colors: InputFlexibleColorArray,
3819                                pos: number[] | null, mode: TileMode, localMatrix?: InputMatrix,
3820                                flags?: number, colorSpace?: ColorSpace): Shader;
3821}
3822
3823/**
3824 * See SkTextBlob.h for more details.
3825 */
3826export interface TextBlobFactory {
3827    /**
3828     * Return a TextBlob with a single run of text.
3829     *
3830     * It does not perform typeface fallback for characters not found in the Typeface.
3831     * It does not perform kerning or other complex shaping; glyphs are positioned based on their
3832     * default advances.
3833     * @param glyphs - if using Malloc'd array, be sure to use CanvasKit.MallocGlyphIDs().
3834     * @param font
3835     */
3836    MakeFromGlyphs(glyphs: InputGlyphIDArray, font: Font): TextBlob;
3837
3838    /**
3839     * Returns a TextBlob built from a single run of text with rotation, scale, and translations.
3840     *
3841     * It uses the default character-to-glyph mapping from the typeface in the font.
3842     * @param str
3843     * @param rsxforms
3844     * @param font
3845     */
3846    MakeFromRSXform(str: string, rsxforms: InputFlattenedRSXFormArray, font: Font): TextBlob;
3847
3848    /**
3849     * Returns a TextBlob built from a single run of text with rotation, scale, and translations.
3850     *
3851     * @param glyphs - if using Malloc'd array, be sure to use CanvasKit.MallocGlyphIDs().
3852     * @param rsxforms
3853     * @param font
3854     */
3855    MakeFromRSXformGlyphs(glyphs: InputGlyphIDArray, rsxforms: InputFlattenedRSXFormArray,
3856                          font: Font): TextBlob;
3857
3858    /**
3859     * Return a TextBlob with a single run of text.
3860     *
3861     * It uses the default character-to-glyph mapping from the typeface in the font.
3862     * It does not perform typeface fallback for characters not found in the Typeface.
3863     * It does not perform kerning or other complex shaping; glyphs are positioned based on their
3864     * default advances.
3865     * @param str
3866     * @param font
3867     */
3868    MakeFromText(str: string, font: Font): TextBlob;
3869
3870    /**
3871     * Returns a TextBlob that has the glyphs following the contours of the given path.
3872     *
3873     * It is a convenience wrapper around MakeFromRSXform and ContourMeasureIter.
3874     * @param str
3875     * @param path
3876     * @param font
3877     * @param initialOffset - the length in pixels to start along the path.
3878     */
3879    MakeOnPath(str: string, path: Path, font: Font, initialOffset?: number): TextBlob;
3880}
3881
3882export interface TextStyleConstructor {
3883    /**
3884     * Fills out all optional fields with defaults. The emscripten bindings complain if there
3885     * is a field undefined and it was expecting a float (for example).
3886     * @param ts
3887     */
3888    new(ts: TextStyle): TextStyle;
3889}
3890
3891export interface TypefaceFactory {
3892    /**
3893     * Create a typeface using Freetype from the specified bytes and return it. CanvasKit supports
3894     * .ttf, .woff and .woff2 fonts. It returns null if the bytes cannot be decoded.
3895     * @param fontData
3896     */
3897    MakeFreeTypeFaceFromData(fontData: ArrayBuffer): Typeface | null;
3898}
3899
3900export interface TypefaceFontProviderFactory {
3901    /**
3902     * Return an empty TypefaceFontProvider
3903     */
3904    Make(): TypefaceFontProvider;
3905}
3906
3907/**
3908 * Functions for manipulating vectors. It is Loosely based off of SkV3 in SkM44.h but Skia
3909 * also has SkVec2 and Skv4. This combines them and works on vectors of any length.
3910 */
3911export interface VectorHelpers {
3912    /**
3913     * Adds 2 vectors together, term by term, returning a new Vector.
3914     * @param a
3915     * @param b
3916     */
3917    add(a: VectorN, b: VectorN): VectorN;
3918
3919    /**
3920     * Returns the cross product of the two vectors. Only works for length 3.
3921     * @param a
3922     * @param b
3923     */
3924    cross(a: Vector3, b: Vector3): Vector3;
3925
3926    /**
3927     * Returns the length(sub(a, b))
3928     * @param a
3929     * @param b
3930     */
3931    dist(a: VectorN, b: VectorN): number;
3932
3933    /**
3934     * Returns the dot product of the two vectors.
3935     * @param a
3936     * @param b
3937     */
3938    dot(a: VectorN, b: VectorN): number;
3939
3940    /**
3941     * Returns the length of this vector, which is always positive.
3942     * @param v
3943     */
3944    length(v: VectorN): number;
3945
3946    /**
3947     * Returns the length squared of this vector.
3948     * @param v
3949     */
3950    lengthSquared(v: VectorN): number;
3951
3952    /**
3953     * Returns a new vector which is v multiplied by the scalar s.
3954     * @param v
3955     * @param s
3956     */
3957    mulScalar(v: VectorN, s: number): VectorN;
3958
3959    /**
3960     * Returns a normalized vector.
3961     * @param v
3962     */
3963    normalize(v: VectorN): VectorN;
3964
3965    /**
3966     * Subtracts vector b from vector a (termwise).
3967     * @param a
3968     * @param b
3969     */
3970    sub(a: VectorN, b: VectorN): VectorN;
3971}
3972
3973/**
3974 * A PosTan is a Float32Array of length 4, representing a position and a tangent vector. In order,
3975 * the values are [px, py, tx, ty].
3976 */
3977export type PosTan = Float32Array;
3978/**
3979 * An Color is represented by 4 floats, typically with values between 0 and 1.0. In order,
3980 * the floats correspond to red, green, blue, alpha.
3981 */
3982export type Color = Float32Array;
3983export type ColorInt = number; // deprecated, prefer Color
3984/**
3985 * An ColorMatrix is a 4x4 color matrix that transforms the 4 color channels
3986 * with a 1x4 matrix that post-translates those 4 channels.
3987 * For example, the following is the layout with the scale (S) and post-transform
3988 * (PT) items indicated.
3989 * RS,  0,  0,  0 | RPT
3990 *  0, GS,  0,  0 | GPT
3991 *  0,  0, BS,  0 | BPT
3992 *  0,  0,  0, AS | APT
3993 */
3994export type ColorMatrix = Float32Array;
3995/**
3996 * An IRect is represented by 4 ints. In order, the ints correspond to left, top,
3997 * right, bottom. See Rect.h for more
3998 */
3999export type IRect = Int32Array;
4000/**
4001 * A Point is represented by 2 floats: (x, y).
4002 */
4003export type Point = Float32Array;
4004/**
4005 * A Rect is represented by 4 floats. In order, the floats correspond to left, top,
4006 * right, bottom. See Rect.h for more
4007 */
4008export type Rect = Float32Array;
4009
4010export interface RectWithDirection {
4011    rect: Rect;
4012    dir: TextDirection;
4013}
4014
4015/**
4016 * An RRect (rectangle with rounded corners) is represented by 12 floats. In order, the floats
4017 * correspond to left, top, right, bottom and then in pairs, the radiusX, radiusY for upper-left,
4018 * upper-right, lower-right, lower-left. See RRect.h for more.
4019 */
4020export type RRect = Float32Array;
4021
4022export type WebGLContextHandle = number;
4023export type AngleInDegrees = number;
4024export type AngleInRadians = number;
4025export type SaveLayerFlag = number;
4026
4027export type TypedArrayConstructor = Float32ArrayConstructor | Int32ArrayConstructor |
4028    Int16ArrayConstructor | Int8ArrayConstructor | Uint32ArrayConstructor |
4029    Uint16ArrayConstructor | Uint8ArrayConstructor;
4030export type TypedArray = Float32Array | Int32Array | Int16Array | Int8Array | Uint32Array |
4031    Uint16Array | Uint8Array;
4032
4033export type ColorIntArray = MallocObj | Uint32Array | number[];
4034/**
4035 * FlattenedPointArray represents n points by 2*n float values. In order, the values should
4036 * be the x, y for each point.
4037 */
4038export type FlattenedPointArray = Float32Array;
4039/**
4040 * FlattenedRectangleArray represents n rectangles by 4*n float values. In order, the values should
4041 * be the top, left, right, bottom point for each rectangle.
4042 */
4043export type FlattenedRectangleArray = Float32Array;
4044
4045export type GlyphIDArray = Uint16Array;
4046/**
4047 * A command is a verb and then any arguments needed to fulfill that path verb.
4048 * InputCommands is a flattened structure of one or more of these.
4049 * Examples:
4050 *   [CanvasKit.MOVE_VERB, 0, 10,
4051 *    CanvasKit.QUAD_VERB, 20, 50, 45, 60,
4052 *    CanvasKit.LINE_VERB, 30, 40]
4053 */
4054export type InputCommands = MallocObj | Float32Array | number[];
4055/**
4056 * VerbList holds verb constants like CanvasKit.MOVE_VERB, CanvasKit.CUBIC_VERB.
4057 */
4058export type VerbList = MallocObj | Uint8Array | number[];
4059/**
4060 * WeightList holds weights for conics when making paths.
4061 */
4062export type WeightList = MallocObj | Float32Array | number[];
4063
4064export type Matrix4x4 = Float32Array;
4065export type Matrix3x3 = Float32Array;
4066export type Matrix3x2 = Float32Array;
4067/**
4068 * Vector3 represents an x, y, z coordinate or vector. It has length 3.
4069 */
4070export type Vector3 = number[];
4071
4072/**
4073 * VectorN represents a vector of length n.
4074 */
4075export type VectorN = number[];
4076
4077/**
4078 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as colors.
4079 * Length 4.
4080 */
4081export type InputColor = MallocObj | Color | number[];
4082/**
4083 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as color matrices.
4084 * Length 20.
4085 */
4086export type InputColorMatrix = MallocObj | ColorMatrix | number[];
4087/**
4088 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as glyph IDs.
4089 * Length n for n glyph IDs.
4090 */
4091export type InputGlyphIDArray = MallocObj | GlyphIDArray | number[];
4092/**
4093 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as flattened points.
4094 * Length 2 * n for n points.
4095 */
4096export type InputFlattenedPointArray = MallocObj | FlattenedPointArray | number[];
4097/**
4098 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as flattened rectangles.
4099 * Length 4 * n for n rectangles.
4100 */
4101export type InputFlattenedRectangleArray = MallocObj | FlattenedRectangleArray | number[];
4102/**
4103 * Some APIs accept a flattened array of colors in one of two ways - groups of 4 float values for
4104 * r, g, b, a or just integers that have 8 bits for each these. CanvasKit will detect which one
4105 * it is and act accordingly. Additionally, this can be an array of Float32Arrays of length 4
4106 * (e.g. Color). This is convenient for things like gradients when matching up colors to stops.
4107 */
4108export type InputFlexibleColorArray = Float32Array | Uint32Array | Float32Array[];
4109/**
4110 * CanvasKit APIs accept a Float32Array or a normal array (of length 2) as a Point.
4111 */
4112export type InputPoint = Point | number[];
4113/**
4114 * CanvasKit APIs accept all of these matrix types. Under the hood, we generally use 4x4 matrices.
4115 */
4116export type InputMatrix = MallocObj | Matrix4x4 | Matrix3x3 | Matrix3x2 | DOMMatrix | number[];
4117/**
4118 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as rectangles.
4119 * Length 4.
4120 */
4121export type InputRect = MallocObj | Rect | number[];
4122/**
4123 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as (int) rectangles.
4124 * Length 4.
4125 */
4126export type InputIRect = MallocObj | IRect | number[];
4127/**
4128 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as rectangles with
4129 * rounded corners. Length 12.
4130 */
4131export type InputRRect = MallocObj | RRect | number[];
4132/**
4133 * This represents n RSXforms by 4*n float values. In order, the values should
4134 * be scos, ssin, tx, ty for each RSXForm. See RSXForm.h for more details.
4135 */
4136export type InputFlattenedRSXFormArray = MallocObj | Float32Array | number[];
4137/**
4138 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory as a vector of 3 floats.
4139 * For example, this is the x, y, z coordinates.
4140 */
4141export type InputVector3 = MallocObj | Vector3 | Float32Array;
4142
4143/**
4144 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory
4145 * for bidi regions. Regions are triples of integers
4146 * [startIdx, stopIdx, bidiLevel]
4147 * where startIdx is inclusive and stopIdx is exclusive.
4148 * Length 3 * n where n is the number of regions.
4149 */
4150export type InputBidiRegions = MallocObj | Uint32Array | number[];
4151
4152/**
4153 * CanvasKit APIs accept normal arrays, typed arrays, or Malloc'd memory for
4154 * words, graphemes or line breaks.
4155 */
4156export type InputWords = MallocObj | Uint32Array | number[];
4157export type InputGraphemes = MallocObj | Uint32Array | number[];
4158export type InputLineBreaks = MallocObj | Uint32Array | number[];
4159
4160/**
4161 * These are the types that webGL's texImage2D supports as a way to get data from as a texture.
4162 * Not listed, but also supported are https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame
4163 */
4164export type TextureSource = TypedArray | HTMLImageElement | HTMLVideoElement | ImageData | ImageBitmap;
4165
4166export type AlphaType = EmbindEnumEntity;
4167export type BlendMode = EmbindEnumEntity;
4168export type BlurStyle = EmbindEnumEntity;
4169export type ClipOp = EmbindEnumEntity;
4170export type ColorChannel = EmbindEnumEntity;
4171export type ColorSpace = EmbindObject<ColorSpace>;
4172export type ColorType = EmbindEnumEntity;
4173export type EncodedImageFormat = EmbindEnumEntity;
4174export type FillType = EmbindEnumEntity;
4175export type FilterMode = EmbindEnumEntity;
4176export type FontEdging = EmbindEnumEntity;
4177export type FontHinting = EmbindEnumEntity;
4178export type MipmapMode = EmbindEnumEntity;
4179export type PaintStyle = EmbindEnumEntity;
4180export type Path1DEffectStyle = EmbindEnumEntity;
4181export type PathOp = EmbindEnumEntity;
4182export type PointMode = EmbindEnumEntity;
4183export type StrokeCap = EmbindEnumEntity;
4184export type StrokeJoin = EmbindEnumEntity;
4185export type TileMode = EmbindEnumEntity;
4186export type VertexMode = EmbindEnumEntity;
4187
4188export type Affinity = EmbindEnumEntity;
4189export type DecorationStyle = EmbindEnumEntity;
4190export type FontSlant = EmbindEnumEntity;
4191export type FontWeight = EmbindEnumEntity;
4192export type FontWidth = EmbindEnumEntity;
4193export type PlaceholderAlignment = EmbindEnumEntity;
4194export type RectHeightStyle = EmbindEnumEntity;
4195export type RectWidthStyle = EmbindEnumEntity;
4196export type TextAlign = EmbindEnumEntity;
4197export type TextBaseline = EmbindEnumEntity;
4198export type TextDirection = EmbindEnumEntity;
4199export type LineBreakType = EmbindEnumEntity;
4200export type TextHeightBehavior = EmbindEnumEntity;
4201
4202export interface AffinityEnumValues extends EmbindEnum {
4203    Upstream: Affinity;
4204    Downstream: Affinity;
4205}
4206
4207export interface AlphaTypeEnumValues extends EmbindEnum {
4208    Opaque: AlphaType;
4209    Premul: AlphaType;
4210    Unpremul: AlphaType;
4211}
4212
4213export interface BlendModeEnumValues extends EmbindEnum {
4214    Clear: BlendMode;
4215    Src: BlendMode;
4216    Dst: BlendMode;
4217    SrcOver: BlendMode;
4218    DstOver: BlendMode;
4219    SrcIn: BlendMode;
4220    DstIn: BlendMode;
4221    SrcOut: BlendMode;
4222    DstOut: BlendMode;
4223    SrcATop: BlendMode;
4224    DstATop: BlendMode;
4225    Xor: BlendMode;
4226    Plus: BlendMode;
4227    Modulate: BlendMode;
4228    Screen: BlendMode;
4229    Overlay: BlendMode;
4230    Darken: BlendMode;
4231    Lighten: BlendMode;
4232    ColorDodge: BlendMode;
4233    ColorBurn: BlendMode;
4234    HardLight: BlendMode;
4235    SoftLight: BlendMode;
4236    Difference: BlendMode;
4237    Exclusion: BlendMode;
4238    Multiply: BlendMode;
4239    Hue: BlendMode;
4240    Saturation: BlendMode;
4241    Color: BlendMode;
4242    Luminosity: BlendMode;
4243}
4244
4245export interface BlurStyleEnumValues extends EmbindEnum {
4246    Normal: BlurStyle;
4247    Solid: BlurStyle;
4248    Outer: BlurStyle;
4249    Inner: BlurStyle;
4250}
4251
4252export interface ClipOpEnumValues extends EmbindEnum {
4253    Difference: ClipOp;
4254    Intersect: ClipOp;
4255}
4256
4257/**
4258 * The currently supported color spaces. These are all singleton values.
4259 */
4260export interface ColorSpaceEnumValues { // not a typical enum, but effectively like one.
4261    // These are all singleton values - don't call delete on them.
4262    readonly SRGB: ColorSpace;
4263    readonly DISPLAY_P3: ColorSpace;
4264    readonly ADOBE_RGB: ColorSpace;
4265
4266    /**
4267     * Returns true if the two color spaces are equal.
4268     * @param a
4269     * @param b
4270     */
4271    Equals(a: ColorSpace, b: ColorSpace): boolean;
4272}
4273
4274export interface ColorChannelEnumValues extends EmbindEnum {
4275    Red: ColorChannel;
4276    Green: ColorChannel;
4277    Blue: ColorChannel;
4278    Alpha: ColorChannel;
4279}
4280
4281export interface ColorTypeEnumValues extends EmbindEnum {
4282    Alpha_8: ColorType;
4283    RGB_565: ColorType;
4284    RGBA_8888: ColorType;
4285    BGRA_8888: ColorType;
4286    RGBA_1010102: ColorType;
4287    RGB_101010x: ColorType;
4288    Gray_8: ColorType;
4289    RGBA_F16: ColorType;
4290    RGBA_F32: ColorType;
4291}
4292
4293export interface DecorationStyleEnumValues extends EmbindEnum {
4294    Solid: DecorationStyle;
4295    Double: DecorationStyle;
4296    Dotted: DecorationStyle;
4297    Dashed: DecorationStyle;
4298    Wavy: DecorationStyle;
4299}
4300
4301export interface FillTypeEnumValues extends EmbindEnum {
4302    Winding: FillType;
4303    EvenOdd: FillType;
4304}
4305
4306export interface FilterModeEnumValues extends EmbindEnum {
4307    Linear: FilterMode;
4308    Nearest: FilterMode;
4309}
4310
4311export interface FontEdgingEnumValues extends EmbindEnum {
4312    Alias: FontEdging;
4313    AntiAlias: FontEdging;
4314    SubpixelAntiAlias: FontEdging;
4315}
4316
4317export interface FontHintingEnumValues extends EmbindEnum {
4318    None: FontHinting;
4319    Slight: FontHinting;
4320    Normal: FontHinting;
4321    Full: FontHinting;
4322}
4323
4324export interface FontSlantEnumValues extends EmbindEnum {
4325    Upright: FontSlant;
4326    Italic: FontSlant;
4327    Oblique: FontSlant;
4328}
4329
4330export interface FontWeightEnumValues extends EmbindEnum {
4331    Invisible: FontWeight;
4332    Thin: FontWeight;
4333    ExtraLight: FontWeight;
4334    Light: FontWeight;
4335    Normal: FontWeight;
4336    Medium: FontWeight;
4337    SemiBold: FontWeight;
4338    Bold: FontWeight;
4339    ExtraBold: FontWeight;
4340    Black: FontWeight;
4341    ExtraBlack: FontWeight;
4342}
4343
4344export interface FontWidthEnumValues extends EmbindEnum {
4345    UltraCondensed: FontWidth;
4346    ExtraCondensed: FontWidth;
4347    Condensed: FontWidth;
4348    SemiCondensed: FontWidth;
4349    Normal: FontWidth;
4350    SemiExpanded: FontWidth;
4351    Expanded: FontWidth;
4352    ExtraExpanded: FontWidth;
4353    UltraExpanded: FontWidth;
4354}
4355
4356/*
4357 *  These values can be OR'd together
4358 */
4359export interface GlyphRunFlagValues {
4360    IsWhiteSpace: number;
4361}
4362
4363export interface ImageFormatEnumValues extends EmbindEnum {
4364    // TODO(kjlubick) When these are compiled in depending on the availability of the codecs,
4365    //   be sure to make these nullable.
4366    PNG: EncodedImageFormat;
4367    JPEG: EncodedImageFormat;
4368    WEBP: EncodedImageFormat;
4369}
4370
4371export interface MipmapModeEnumValues extends EmbindEnum {
4372    None: MipmapMode;
4373    Nearest: MipmapMode;
4374    Linear: MipmapMode;
4375}
4376
4377export interface PaintStyleEnumValues extends EmbindEnum {
4378    Fill: PaintStyle;
4379    Stroke: PaintStyle;
4380}
4381
4382export interface Path1DEffectStyleEnumValues extends EmbindEnum {
4383    // Translate the shape to each position
4384    Translate: Path1DEffectStyle;
4385    // Rotate the shape about its center
4386    Rotate: Path1DEffectStyle;
4387    // Transform each point and turn lines into curves
4388    Morph: Path1DEffectStyle;
4389}
4390
4391export interface PathOpEnumValues extends EmbindEnum {
4392    Difference: PathOp;
4393    Intersect: PathOp;
4394    Union: PathOp;
4395    XOR: PathOp;
4396    ReverseDifference: PathOp;
4397}
4398
4399export interface PlaceholderAlignmentEnumValues extends EmbindEnum {
4400    Baseline: PlaceholderAlignment;
4401    AboveBaseline: PlaceholderAlignment;
4402    BelowBaseline: PlaceholderAlignment;
4403    Top: PlaceholderAlignment;
4404    Bottom: PlaceholderAlignment;
4405    Middle: PlaceholderAlignment;
4406}
4407
4408export interface PointModeEnumValues extends EmbindEnum {
4409    Points: PointMode;
4410    Lines: PointMode;
4411    Polygon: PointMode;
4412}
4413
4414export interface RectHeightStyleEnumValues extends EmbindEnum {
4415    Tight: RectHeightStyle;
4416    Max: RectHeightStyle;
4417    IncludeLineSpacingMiddle: RectHeightStyle;
4418    IncludeLineSpacingTop: RectHeightStyle;
4419    IncludeLineSpacingBottom: RectHeightStyle;
4420    Strut: RectHeightStyle;
4421}
4422
4423export interface RectWidthStyleEnumValues extends EmbindEnum {
4424    Tight: RectWidthStyle;
4425    Max: RectWidthStyle;
4426}
4427
4428export interface StrokeCapEnumValues extends EmbindEnum {
4429    Butt: StrokeCap;
4430    Round: StrokeCap;
4431    Square: StrokeCap;
4432}
4433
4434export interface StrokeJoinEnumValues extends EmbindEnum {
4435    Bevel: StrokeJoin;
4436    Miter: StrokeJoin;
4437    Round: StrokeJoin;
4438}
4439
4440export interface TextAlignEnumValues extends EmbindEnum {
4441    Left: TextAlign;
4442    Right: TextAlign;
4443    Center: TextAlign;
4444    Justify: TextAlign;
4445    Start: TextAlign;
4446    End: TextAlign;
4447}
4448
4449export interface TextBaselineEnumValues extends EmbindEnum {
4450    Alphabetic: TextBaseline;
4451    Ideographic: TextBaseline;
4452}
4453
4454export interface TextDirectionEnumValues extends EmbindEnum {
4455    LTR: TextDirection;
4456    RTL: TextDirection;
4457}
4458
4459export interface LineBreakTypeEnumValues extends EmbindEnum {
4460    SoftLineBreak: LineBreakType;
4461    HardtLineBreak: LineBreakType;
4462}
4463
4464export interface TextHeightBehaviorEnumValues extends EmbindEnum {
4465    All: TextHeightBehavior;
4466    DisableFirstAscent: TextHeightBehavior;
4467    DisableLastDescent: TextHeightBehavior;
4468    DisableAll: TextHeightBehavior;
4469}
4470
4471export interface TileModeEnumValues extends EmbindEnum {
4472    Clamp: TileMode;
4473    Decal: TileMode;
4474    Mirror: TileMode;
4475    Repeat: TileMode;
4476}
4477
4478export interface VertexModeEnumValues extends EmbindEnum {
4479    Triangles: VertexMode;
4480    TrianglesStrip: VertexMode;
4481    TriangleFan: VertexMode;
4482}
4483