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