Skip to content

Commit 28a906c

Browse files
committed
fix slow types
1 parent 1c905eb commit 28a906c

File tree

10 files changed

+100
-82
lines changed

10 files changed

+100
-82
lines changed

deno.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"version": "0.5.6",
55
"exports": "./mod.ts",
66

7+
"exclude": ["skia", "scripts", "bench", "native", "test", "testdata"],
8+
79
"tasks": {
810
"build": "cd native/build && CC=clang CXX=clang++ cmake .. && cmake --build . --config Release",
911
"build-win": "rm -rf native/build && mkdir native/build && cd native/build && cmake .. -G \"Visual Studio 17 2022\" -T ClangCL && cmake --build . --config Release",

src/canvas.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ export class Canvas {
6161
[_gpu] = false;
6262
[_ctx]: CanvasRenderingContext2D;
6363

64-
get _unsafePointer() {
64+
get _unsafePointer(): Deno.PointerValue {
6565
return this[_ptr];
6666
}
6767

68-
get width() {
68+
get width(): number {
6969
return this[_width];
7070
}
7171

7272
set width(width: number) {
7373
this.resize(width, this[_height]);
7474
}
7575

76-
get height() {
76+
get height(): number {
7777
return this[_height];
7878
}
7979

@@ -82,7 +82,7 @@ export class Canvas {
8282
}
8383

8484
/** Whether Canvas is GPU backed */
85-
get gpu() {
85+
get gpu(): boolean {
8686
return this[_gpu];
8787
}
8888

@@ -123,7 +123,7 @@ export class Canvas {
123123
* Encode the canvas image into a buffer in specified format
124124
* and quality.
125125
*/
126-
encode(format: ImageFormat = "png", quality = 100) {
126+
encode(format: ImageFormat = "png", quality = 100): Uint8Array {
127127
const bufptr = sk_canvas_encode_image(
128128
this[_ptr],
129129
CFormat[format],
@@ -146,7 +146,7 @@ export class Canvas {
146146
/**
147147
* Creates a data url from the canvas data
148148
*/
149-
toDataURL(format: ImageFormat = "png", quality = 100) {
149+
toDataURL(format: ImageFormat = "png", quality = 100): string {
150150
const buffer = this.encode(format, quality);
151151
return `data:image/${format};base64,${encodeBase64(buffer)}`;
152152
}
@@ -161,7 +161,7 @@ export class Canvas {
161161
height?: number,
162162
into?: Uint8Array,
163163
colorSpace: ColorSpace = "srgb",
164-
) {
164+
): Uint8Array {
165165
width = width ?? this[_width];
166166
height = height ?? this[_height];
167167
const pixels = into ?? new Uint8Array(width * height * 4);
@@ -194,7 +194,7 @@ export class Canvas {
194194
/**
195195
* Resizes the Canvas to the specified dimensions
196196
*/
197-
resize(width: number, height: number) {
197+
resize(width: number, height: number): void {
198198
if (this[_width] === width && this[_height] === height) return;
199199
sk_canvas_set_size(this[_ptr], width, height);
200200
this[_width] = width;
@@ -210,7 +210,7 @@ export class Canvas {
210210
if (this[_gpu]) sk_canvas_flush(this[_ptr]);
211211
}
212212

213-
[Symbol.for("Jupyter.display")]() {
213+
[Symbol.for("Jupyter.display")](): Record<string, string> {
214214
return {
215215
"image/png": encodeBase64(this.encode("png")),
216216
};
@@ -223,6 +223,6 @@ export class Canvas {
223223
* Only pass `gpu: true` if you have an OpenGL context initialized
224224
* and made current already.
225225
*/
226-
export function createCanvas(width: number, height: number, gpu?: boolean) {
226+
export function createCanvas(width: number, height: number, gpu?: boolean): Canvas {
227227
return new Canvas(width, height, gpu);
228228
}

0 commit comments

Comments
 (0)