@motion-script/canvaskit 0.1.0

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