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